Skip to content

Commit

Permalink
Fixed captcha, renamed PDF brick to Pdf.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 22, 2011
1 parent 843743c commit 15a279e
Show file tree
Hide file tree
Showing 40 changed files with 316 additions and 197 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ You can now login with 'admin' and the password you used to make the site.
=== 1. Original in debian etch (might need to replace jpeg by libjpeg62)
# aptitude install build-essential apache2 mysql-server libmagick9-dev gs-gpl libssl-dev gettext libgettext-ruby libreadline5 libreadline5-dev zlib1g-dev libncurses5 libncurses5-dev unzip liburi-perl libjpeg-dev subversion ssh sudo awstats

If you want to enable LateX (PDF generation)
If you want to enable LateX (Pdf generation)
tetex-bin tetex-extra latex-ucs

For math mode (inline formulas), you will need
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def create

@comment = secure(Comment) { Comment.new(filter_attributes(params[:comment])) }

save_if_not_spam(@comment, params)
if should_save(@comment, params)
@comment.save
else
#...
end

respond_to do |format|
if @comment.errors.empty?
Expand All @@ -33,7 +37,8 @@ def create
format.js
format.xml { head :created, :location => comment_path(@node) }
else
format.html { render :action => "new" }
flash[:error] = error_messages_for(:comment, :object => @comment)
format.html { redirect_to zen_path(@node) }
format.js
format.xml { render :xml => @comment.errors.to_xml }
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Comment < ActiveRecord::Base
:discussion_id => Number,
:user_name => {:class => String, :nil => true},
:user => {:class => 'User', :nil => true},
:author => Node.author_proc
:author => Node.author_proc,
:author_name => String

safe_context :replies => ['Comment'], :node => 'Node'

Expand Down
16 changes: 9 additions & 7 deletions app/views/comments/index.rhtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<h2 class='title'><%= _('comments') %></h2>
<div id='comment_errors'></div>

<%= will_paginate @comments %>
<ul class='comments' id='comments_list'>
<%= render :partial=>'comments/li', :collection=>@comments %>
</ul>
<div id='comments'>
<div id='comment_errors'></div>
<%= will_paginate @comments %>
<ul class='comments' id='comments_list'>
<%= render :partial=>'comments/li', :collection=>@comments %>
</ul>


<div id='bin'>
<%= render :partial=>'comments/bin' %>
<div id='bin'>
<%= render :partial=>'comments/bin' %>
</div>
</div>
50 changes: 34 additions & 16 deletions app/views/zafu/default/Node-admin.zafu
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<r:if test='visitor.is_anon?' do='not_found'/>
<html xmlns='http://www.w3.org/1999/xhtml' lang='#{v.lang}' xml:lang='en'>
<html xmlns='http://www.w3.org/1999/xhtml' lang='#{v.lang}' xml:lang='en' do='load' dictionary='translations' missing='ignore'>
<head do='void' name='head'>
<title do='title_for_layout' do='show' attr='title' name='page_title'>page title</title>
<!-- link href='favicon.png' rel='shortcut icon' type='image/png' / -->
<meta http-equiv='Content-type' content='text/html; charset=utf-8' />
<r:void name='stylesheets'>
<r:stylesheets/>
<r:stylesheets list='admin,backend'/>
<r:stylesheets list='backend,admin,comment'/>
</r:void>

<r:javascripts/>
Expand Down Expand Up @@ -100,13 +100,31 @@

<div id='browser'>
<div class='wrap'>
<div id='query'>
<div class='search' do='filter' live='true'>
<r:input param='qb'/>
</div>
<div id='qb_list' do='block' do='query' default='nodes in site limit 30 paginate p' select='#{params[:qb] || "nodes in site"} limit 30 paginate p' set_ref='this' set_epar='"qb"'>
<div class='pages'><r:t>page</r:t>: <r:link page='list' page_count='6' update='qb_list' encode_params='#{epar}'/> (<r:count/> <r:t>rec.</r:t>)</div>
<ul>
<r:include template='$default/Node-admin' part='elem'/>
</ul>
<r:elsif test='query_errors'>
<div class='pages error' do='query_errors'/>
</r:elsif>
<r:else>
<div class='pages' do='t'>not_found</div>
<ul></ul>
</r:else>
</div>
</div> <!-- #query -->
<div id='parents'>
<div class='search' do='filter' live='true'>
<input type='text' name='f'/>
<r:select param='k' root_class='Node' attr='kpath'/>
<r:input param='f1'/>
<r:select param='k1' root_class='Node' attr='kpath'/>
</div>
<div id='par_list' do='block' do='children where kpath like "#{params[:k]}%" and title like "%#{params[:f]}%" from parent from parent limit 30 paginate p' set_ref='parent'>
<div class='pages'><r:t>page</r:t>: <r:link page='list' page_count='6' update='par_list' encode_params='f'/> (<r:count/> <r:t>records</r:t>)</div>
<div id='par_list' do='block' do='children where kpath like "#{params[:k1]}%" and title like "%#{params[:f1]}%" from parent from parent limit 30 paginate p' set_ref='parent' set_epar='"k1,f1,qb"'>
<div class='pages'><r:t>page</r:t>: <r:link page='list' page_count='6' update='par_list' encode_params='#{epar}'/> (<r:count/> <r:t>rec.</r:t>)</div>
<ul>
<li do='each' alt_class='stripe' on_if='id == ref.id' name='elem'>
<r:Image?>
Expand All @@ -115,7 +133,7 @@
<img src='#{vclass.icon || "/images/brick.png"}'/>
</r:else>
</r:Image?>
<r:link mode='admin'>
<r:link mode='admin' encode_params='#{epar}'>
<span class='id' do='id'/>
<r:Document?>
<r:show text='#{title.limit(14)}.#{ext}'/>
Expand All @@ -140,13 +158,13 @@
</div> <!-- #parents -->
<div id='siblings'>
<div class='search' do='filter' live='true'>
<input type='text' name='f'/>
<r:select param='k' root_class='Node' attr='kpath'/>
<r:input param='f2'/>
<r:select param='k2' root_class='Node' attr='kpath'/>
</div>
<div id='sib_list' do='block' do='children where kpath like "#{params[:k]}%" and title like "%#{params[:f]}%" from parent limit 30 paginate p' set_ref='this'>
<div class='pages'><r:t>page</r:t>: <r:link page='list' page_count='6' update='sib_list' encode_params='f'/> (<r:count/> <r:t>records</r:t>)</div>
<div id='sib_list' do='block' do='children where kpath like "#{params[:k2]}%" and title like "%#{params[:f2]}%" from parent limit 30 paginate p' set_ref='this' set_epar='"k2,f2,qb"'>
<div class='pages'><r:t>page</r:t>: <r:link page='list' page_count='6' update='sib_list' encode_params='#{epar}'/> (<r:count/> <r:t>rec.</r:t>)</div>
<ul>
<r:include template='$default/Node-admin' part='elem' method='void'/>
<r:include template='$default/Node-admin' part='elem'/>
</ul>
<r:else>
<!-- no parent, just show self -->
Expand All @@ -159,11 +177,11 @@
</div> <!-- #siblings -->
<div id='children'>
<div class='search' do='filter' live='true'>
<input type='text' name='f'/>
<r:select param='k' root_class='Node' attr='kpath'/>
<r:input param='f3'/>
<r:select param='k3' root_class='Node' attr='kpath'/>
</div>
<div id='ch_list' do='block' do='children where kpath like "#{params[:k]}%" and title like "%#{params[:f]}%" limit 30 paginate p'>
<div class='pages'><r:t>page</r:t>: <r:link page='list' page_count='6' update='ch_list' encode_params='f'/> (<r:count/> <r:t>records</r:t>)</div>
<div id='ch_list' do='block' do='children where kpath like "#{params[:k3]}%" and title like "%#{params[:f3]}%" limit 30 paginate p' set_epar='"k3,f3,qb"'>
<div class='pages'><r:t>page</r:t>: <r:link page='list' page_count='6' update='ch_list' encode_params='#{epar}'/> (<r:count/> <r:t>rec.</r:t>)</div>
<ul>
<r:each set_ref='main' do='include' template='$default/Node-admin' part='elem' method='void'/>
<li class='add' do='add' do='t'>add_object</li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/zafu/default/Node.zafu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<r:void name='stylesheets'>
<r:stylesheets media='all'/>
<link href="img/style.css" rel="Stylesheet" type="text/css"/>
<r:stylesheets list='default'/>
</r:void>

<r:javascripts/>
Expand Down
5 changes: 3 additions & 2 deletions bricks/captcha/lib/bricks/captcha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ module ControllerMethods
include ReCaptcha::AppHelper

private
def save_if_not_spam(obj, params)
(!visitor.is_anon? || validate_recap(params, obj.errors, :rcc_pub => current_site.prop['recaptcha_pub'], :rcc_priv => current_site.prop['recaptcha_priv'])) && obj.save
def should_save(obj, params)
!visitor.is_anon? ||
validate_recap(params, obj.errors, :rcc_pub => current_site.prop['recaptcha_pub'], :rcc_priv => current_site.prop['recaptcha_priv'])
end
end

Expand Down
10 changes: 5 additions & 5 deletions bricks/pdf/README
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ There is one method "render" that takes a hash as argument.

== Examples

Bricks::PDF.engine = 'prince'
Bricks::Pdf.engine = 'prince'

Bricks::PDF.render :input => "myfile.html"
Bricks::Pdf.render :input => "myfile.html"
=> STDOUT

Bricks::PDF.render :input => "myfile.html", :output => "out.pdf"
Bricks::Pdf.render :input => "myfile.html", :output => "out.pdf"
=> out.pdf (file)

Bricks::PDF.render :data => "This is text to render."
Bricks::Pdf.render :data => "This is text to render."
=> STDOUT (strings)

Bricks::PDF.render :data => "This is text to render.", :output => "out.pdf"
Bricks::Pdf.render :data => "This is text to render.", :output => "out.pdf"
=> out.pdf (file)
22 changes: 11 additions & 11 deletions bricks/pdf/lib/bricks/pdf.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
=begin rdoc
PDF is module to render file or IO streams (strings obviously) into pdf.
Pdf is module to render file or IO streams (strings obviously) into pdf.
Examples:
Bricks::PDF.engine = 'Xhtml2pdf'
Bricks::Pdf.engine = 'Xhtml2pdf'
Bricks::PDF.render_file "myfile.html" => STDOUT (strings)
Bricks::PDF.render_file "myfile.html", "out.pdf" => out.pdf (file)
Bricks::Pdf.render_file "myfile.html" => STDOUT (strings)
Bricks::Pdf.render_file "myfile.html", "out.pdf" => out.pdf (file)
Bricks::PDF.render_string "This is text to render." => STDOUT (strings)
Bricks::PDF.render_string "This is text to render.", "out.pdf" => out.pdf (file)
Bricks::Pdf.render_string "This is text to render." => STDOUT (strings)
Bricks::Pdf.render_string "This is text to render.", "out.pdf" => out.pdf (file)
=end

module Bricks
module PDF
module Pdf
extend self
# Wrapper around pdf engines
module Engine
Expand All @@ -31,10 +31,10 @@ class InvalidEngine < Error
end

def engine=(engine_name)
engine_module = Zena.resolve_const("Bricks::PDF::Engine::#{engine_name.to_s.capitalize}")
engine_module = Zena.resolve_const("Bricks::Pdf::Engine::#{engine_name.to_s.capitalize}")
extend engine_module
rescue NameError
raise PDF::InvalidEngine, "Could not load pdf engine '#{engine_name}'."
raise Pdf::InvalidEngine, "Could not load pdf engine '#{engine_name}'."
end

def render(options)
Expand Down Expand Up @@ -66,7 +66,7 @@ def render_to_pdf(opts)

target_file = Tempfile.new('trg').path + '.pdf'

data = Bricks::PDF.render(get_render_auth_params.merge(
data = Bricks::Pdf.render(get_render_auth_params.merge(
:data => data,
:output => target_file
))
Expand Down Expand Up @@ -106,5 +106,5 @@ def render_to_pdf(opts)

module ZafuMethods
end # ZafuMethods
end # PDF
end # Pdf
end # Bricks
4 changes: 2 additions & 2 deletions bricks/pdf/lib/bricks/pdf/engine/prince.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Bricks
module PDF
module Pdf
module Engine
module Prince
def command(opts)
Expand Down Expand Up @@ -31,7 +31,7 @@ def command(opts)
end
end # Prince
end # Engine
end # PDF
end # Pdf
end # Bricks


Expand Down
4 changes: 2 additions & 2 deletions bricks/pdf/lib/bricks/pdf/engine/xhtml2pdf.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Bricks
module PDF
module Pdf
module Engine
module Xhtml2pdf
# Not supported until they have http auth and base url settings.
end # Xhtml2pdf
end # Engine
end # PDF
end # Pdf
end # Bricks
10 changes: 5 additions & 5 deletions bricks/pdf/lib/bricks/pdf/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
# end

module Bricks
module PDF
module Pdf
class Install

# Utility to install library necessary to PDF on unix like machine.
# Utility to install library necessary to Pdf on unix like machine.
#
# To install xhtml2pdf and his dependencies, see PDF::xhtml2pdf in zena/tasks.rb
# To install xhtml2pdf and his dependencies, see Pdf::xhtml2pdf in zena/tasks.rb

include FileUtils::Verbose

attr_reader :url, :file, :md5, :sha1, :force

def self.from_url url, opts={}
tmpf = Tempfile.new('PDF').path
tmpf = Tempfile.new('Pdf').path
install_dir = "#{tmpf}_d"
FileUtils.mkpath(install_dir)
in_dir(install_dir) do
Expand Down Expand Up @@ -111,7 +111,7 @@ def do_checksum?
end

end # Install
end # PDF
end # Pdf
end # Bricks


Expand Down
8 changes: 4 additions & 4 deletions bricks/pdf/test/engines/test_prince.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
require 'bricks/pdf/engine/prince'

class TestPrince < Test::Unit::TestCase
context 'With a Prince based PDF engine' do
context 'With a Prince based Pdf engine' do
subject do
Module.new do
extend Bricks::PDF
extend Bricks::PDF::Engine::Prince
extend Bricks::Pdf
extend Bricks::Pdf::Engine::Prince
end
end

should_behave_as_pdf_engine
end # With a Prince based PDF engine
end # With a Prince based Pdf engine
end
8 changes: 4 additions & 4 deletions bricks/pdf/test/engines/test_xhtml2pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
require 'bricks/pdf/engine/xhtml2pdf'

class TestXhtml2pdf < Test::Unit::TestCase
context 'With a Prince based PDF engine' do
context 'With a Prince based Pdf engine' do
subject do
Module.new do
extend Bricks::PDF
extend Bricks::PDF::Engine::Xhtml2pdf
extend Bricks::Pdf
extend Bricks::Pdf::Engine::Xhtml2pdf
end
end

should_behave_as_pdf_engine
end # With a Xhtml2pdf based PDF engine
end # With a Xhtml2pdf based Pdf engine
end
4 changes: 2 additions & 2 deletions bricks/pdf/test/shoulda_macros/shoulda_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def self.should_behave_as_pdf_engine
end

should 'fill STDOUT if no destination is specified' do
assert_match %r{^%PDF}, subject.render(:input => contact_html)
assert_match %r{^%Pdf}, subject.render(:input => contact_html)
end
end

Expand All @@ -40,7 +40,7 @@ def self.should_behave_as_pdf_engine
end

should 'fill STDOUT if no destination is specified' do
assert_match %r{^%PDF}, subject.render(:data => '<html>Hello World</html>')
assert_match %r{^%Pdf}, subject.render(:data => '<html>Hello World</html>')
end
end

Expand Down
4 changes: 2 additions & 2 deletions bricks/pdf/zena/init.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'bricks/pdf'

Bricks::PDF.engine = Bricks::CONFIG['pdf']['engine']
Bricks::Pdf.engine = Bricks::CONFIG['pdf']['engine']

Zena::Use.module Bricks::PDF
Zena::Use.module Bricks::Pdf

0 comments on commit 15a279e

Please sign in to comment.