Skip to content

Commit

Permalink
Fixed white-space issues by replacing all code that does <% .. -%> fo…
Browse files Browse the repository at this point in the history
…r <% .. %>.
  • Loading branch information
gaspard committed Jan 24, 2011
1 parent 0c8f5ac commit 311ddd1
Show file tree
Hide file tree
Showing 34 changed files with 158 additions and 117 deletions.
2 changes: 1 addition & 1 deletion bricks/captcha/lib/bricks/captcha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def r_captcha
return parser_error("recaptcha keys not set") unless current_site.prop['recaptcha_pub'] && current_site.prop['recaptcha_priv']
res = "<%= get_captcha(:rcc_pub => #{visitor.site.prop['recaptcha_pub'].inspect}, :rcc_priv => #{visitor.site.prop['recaptcha_priv'].inspect}#{get_recaptcha_params}) %>"
res += expand_with
"<% if visitor.is_anon? -%>#{@markup.wrap(res)}<% end -%>"
"<% if visitor.is_anon? %>#{@markup.wrap(res)}<% end %>"
end

def r_mail_hide
Expand Down
10 changes: 5 additions & 5 deletions lib/zena/use/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ def r_login_link

out markup.wrap(expand_if("visitor.is_anon?", self.node, else_markup))
else
out "<% if visitor.is_anon? -%>"
out "<% if visitor.is_anon? %>"
out "<%= link_to #{_('login').inspect}, login_path %>"
out "<% else -%>"
out "<% else %>"
out "<%= link_to #{_('logout').inspect}, logout_path %>"
out "<% end -%>"
out "<% end %>"
end
end

def r_visitor_link
out "<% if !visitor.is_anon? -%>"
out "<% if !visitor.is_anon? %>"
if dynamic_blocks?
@markup.tag ||= 'a'
link = '<%= user_path(visitor) %>'
Expand All @@ -215,7 +215,7 @@ def r_visitor_link
else
out wrap("<%= link_to visitor.node.title, user_path(visitor) %>")
end
out "<% end -%>"
out "<% end %>"
end

def r_action
Expand Down
14 changes: 7 additions & 7 deletions lib/zena/use/ajax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def process_drag
js_options << (%w{true false}.include?(revert) ? revert : revert.inspect)
end

markup.pre_wrap[:drag] = "#{handle}<% add_drag_id(\"#{node.dom_id(:dom_prefix => @drag_prefix, :erb => false)}\", #{js_options.join(', ').inspect}) -%>"
markup.pre_wrap[:drag] = "#{handle}<% add_drag_id(\"#{node.dom_id(:dom_prefix => @drag_prefix, :erb => false)}\", #{js_options.join(', ').inspect}) %>"
end

# Display an input field to filter a remote block
Expand Down Expand Up @@ -263,7 +263,7 @@ def r_filter
end
out "</div></form>"
if @params[:live] || @params[:update]
out "<% filter_form(#{node}, \"#{dom_id}_f\") -%>"
out "<% filter_form(#{node}, \"#{dom_id}_f\") %>"
end
end

Expand Down Expand Up @@ -304,7 +304,7 @@ def r_drop
end

query_params << ", :url => #{make_href(self.name, :action => 'drop')}"
markup.pre_wrap[:drop] = "<% add_drop_id(\"#{dom_id}\"#{query_params}) -%>"
markup.pre_wrap[:drop] = "<% add_drop_id(\"#{dom_id}\"#{query_params}) %>"
r_block
end

Expand All @@ -320,7 +320,7 @@ def r_toggle
dom_id = node.dom_id(:erb => false)
markup.set_id(node.dom_id)
markup.append_param(:class, 'toggle')
out "<% add_toggle_id(\"#{dom_id}\", #{var.inspect}, #{RubyLess.translate_string(self, role)}) { #{finder} } -%>#{expand_with}"
out "<% add_toggle_id(\"#{dom_id}\", #{var.inspect}, #{RubyLess.translate_string(self, role)}) { #{finder} } %>#{expand_with}"
end

def process_toggle
Expand Down Expand Up @@ -350,7 +350,7 @@ def process_toggle
markup.tag ||= 'div'

markup.append_param(:class, 'toggle')
markup.pre_wrap[:toggle] = "<% add_toggle_id(\"#{dom_id}\", #{"#{var}_tog".inspect}, #{RubyLess.translate_string(self, role)}) { #{finder} } -%>"
markup.pre_wrap[:toggle] = "<% add_toggle_id(\"#{dom_id}\", #{"#{var}_tog".inspect}, #{RubyLess.translate_string(self, role)}) { #{finder} } %>"
end

def r_unlink
Expand Down Expand Up @@ -383,7 +383,7 @@ def r_unlink
opts[:default_text] = _('btn_tiny_del')
@params[:class] ||= 'unlink'

out "<% if #{node}.can_write? && #{node}.link_id -%>#{wrap(make_link(opts))}<% end -%>"
out "<% if #{node}.can_write? && #{node}.link_id %>#{wrap(make_link(opts))}<% end %>"

#tag_to_remote
#"<%= tag_to_remote({:url => node_path(#{node_id}) + \"#{opts[:method] != :put ? '/zafu' : ''}?#{action.join('&')}\", :method => #{opts[:method].inspect}}) %>"
Expand All @@ -393,7 +393,7 @@ def r_unlink
# else
# inner = _('btn_tiny_del')
# end
# out "#{inner}</a><% else -%>#{inner}<% end -%>"
# out "#{inner}</a><% else %>#{inner}<% end %>"
#elsif node.will_be?(DataEntry)
# text = get_text_for_erb
# if text.blank?
Expand Down
22 changes: 11 additions & 11 deletions lib/zena/use/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def display_calendar
return unless finder
return parser_error("invalid class (#{klass})") unless klass.ancestors.include?(Node)
cell_code = "<% if #{list_var} = nodes_#{list_var}[cal_#{list_var}.strftime('%Y-%m-%d %H')] -%>#{expand_with(:in_if => true, :list => list_var, :date => "cal_#{list_var}", :saved_template => nil, :dom_prefix => nil, :in_calendar => true)}<% end -%>"
cell_code = "<% if #{list_var} = nodes_#{list_var}[cal_#{list_var}.strftime('%Y-%m-%d %H')] %>#{expand_with(:in_if => true, :list => list_var, :date => "cal_#{list_var}", :saved_template => nil, :dom_prefix => nil, :in_calendar => true)}<% end %>"
render_html_tag(calendar_code(finder, "", cell_code, "", params))
end
Expand Down Expand Up @@ -226,7 +226,7 @@ def assign_calendar(as_role)
# ... B (other node)
# calendar (in B context) ---- role --->
cell_prefix_code = "<span><%= day_#{list_var}.strftime('%d').to_i -%></span><ul>"
cell_prefix_code = "<span><%= day_#{list_var}.strftime('%d').to_i %></span><ul>"
cell_code = "<%= #{list_var} = nodes_#{list_var}[cal_#{list_var}.strftime('%Y-%m-%d %H')]; #{node}.linked_node = #{list_var} ? #{list_var}.first : nil; cal_assign_cell(#{node}, #{role.inspect}, #{@params[:used].inspect}, params[:s] || @node.zip, cal_#{list_var}, #{template_url.inspect}) %>"
cell_postfix_code = "</ul>"
render_html_tag(calendar_code(finder, cell_prefix_code, cell_code, cell_postfix_code, params))
Expand Down Expand Up @@ -255,15 +255,15 @@ def calendar_code(finder, cell_prefix_code, cell_code, cell_postfix_code, params
hours << 0
hours = hours.uniq.sort
# I feel all this would be much better if we could use "each_group" but then how do we access hours ?
week_code = "<% week.step(week+6,1) do |day_#{list_var}| -%>
<td<%= cal_class(day_#{list_var},#{current_date}) %>>#{cell_prefix_code}<% #{hours.inspect}.each do |set_hour|; cal_#{list_var} = Time.utc(day_#{list_var}.year,day_#{list_var}.month,day_#{list_var}.day,set_hour) -%>#{cell_code}<% end -%>#{cell_postfix_code}</td>
<% end -%>"
week_code = "<% week.step(week+6,1) do |day_#{list_var}| %>
<td<%= cal_class(day_#{list_var},#{current_date}) %>>#{cell_prefix_code}<% #{hours.inspect}.each do |set_hour|; cal_#{list_var} = Time.utc(day_#{list_var}.year,day_#{list_var}.month,day_#{list_var}.day,set_hour) %>#{cell_code}<% end %>#{cell_postfix_code}</td>
<% end %>"
(@context[:vars] ||= []) << "hour"
else
hours = nil
week_code = "<% week.step(week+6,1) do |day_#{list_var}| -%>
<td<%= cal_class(day_#{list_var},#{current_date}) %>><% cal_#{list_var} = Time.utc(day_#{list_var}.year,day_#{list_var}.month,day_#{list_var}.day) -%>#{cell_prefix_code}#{cell_code}#{cell_postfix_code}</td>
<% end -%>"
week_code = "<% week.step(week+6,1) do |day_#{list_var}| %>
<td<%= cal_class(day_#{list_var},#{current_date}) %>><% cal_#{list_var} = Time.utc(day_#{list_var}.year,day_#{list_var}.month,day_#{list_var}.day) %>#{cell_prefix_code}#{cell_code}#{cell_postfix_code}</td>
<% end %>"
end
res = %Q{
Expand All @@ -274,12 +274,12 @@ def calendar_code(finder, cell_prefix_code, cell_code, cell_postfix_code, params
</h3>
<table cellspacing='0' class='#{size}cal#{@params[:assign_as] ? " assign" : ''}'>
<tr class='head'><%= cal_day_names(#{size.inspect}) %></tr>
<% start_date, end_date = cal_start_end(#{current_date}, #{type.inspect}) -%>
<% cal_weeks(#{ref_date.to_sym.inspect}, #{finder}, start_date, end_date, #{hours.inspect}) do |week, nodes_#{list_var}| -%>
<% start_date, end_date = cal_start_end(#{current_date}, #{type.inspect}) %>
<% cal_weeks(#{ref_date.to_sym.inspect}, #{finder}, start_date, end_date, #{hours.inspect}) do |week, nodes_#{list_var}| %>
<tr class='body'>
#{week_code}
</tr>
<% end -%>
<% end %>
</table>}
end
=end
Expand Down
20 changes: 13 additions & 7 deletions lib/zena/use/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ def self.visitor_node_proc
end
end


include RubyLess
safe_method :start => {:method => 'start_node', :class => Node}
safe_method :start => Proc.new {|h, r, s| {:method => 'start_node', :class => VirtualClass['Node']}}
safe_method :visitor => User
safe_method :visitor_node => visitor_node_proc
safe_method :main => {:method => '@node', :class => Node}
safe_method :root => {:method => 'visitor.site.root_node', :class => Node, :nil => true}
safe_method :main => Proc.new {|h, r, s| {:method => '@node', :class => VirtualClass['Node']}}
safe_method :root => Proc.new {|h, r, s| {:method => 'visitor.site.root_node', :class => VirtualClass['Node'], :nil => true}}
safe_method :site => {:class => Site, :method => 'visitor.site'}

# Group an array of records by key.
Expand Down Expand Up @@ -145,6 +144,13 @@ def page_numbers(current, count, join_string = nil, max_count = nil)

module ZafuMethods

# Resolve class for @post ==> Post, etc.
def get_class(class_name)
VirtualClass[class_name] || super
rescue
nil
end

# Enter a new context (<r:context find='all' select='pages'>). This is the same as '<r:pages>...</r:pages>'). It is
# considered better style to use '<r:pages>...</r:pages>' instead of the more general '<r:context>' because the tags
# give a clue on the context at start and end. Another way to open a context is the 'do' syntax: "<div do='pages'>...</div>".
Expand Down Expand Up @@ -180,11 +186,11 @@ def r_group
end

#if sort_block
# out "<% grp_#{list_var} = sort_array(#{group_array}) #{sort_block} -%>"
# out "<% grp_#{list_var} = sort_array(#{group_array}) #{sort_block} %>"
#else
#end
method = "group_array(#{node}) {|e| #{key}}"
out "<% if #{var} = #{method} -%>"
out "<% if #{var} = #{method} %>"
open_node_context({:method => method}, :node => node.move_to(var, [node.klass], :query => node.opts[:query])) do
if child['each_group']
out expand_with
Expand All @@ -193,7 +199,7 @@ def r_group
r_each
end
end
out "<% end -%>"
out "<% end %>"

#if descendant('each_group')
# out expand_with(:group => var)
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/dates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def r_main_date
return parser_error("should evaluate to a String or Time (found #{code.klass})")
end
v = get_var_name('set_var', 'main_date')
out "<% #{v} = #{code} -%>"
out "<% #{v} = #{code} %>"
set_context_var('set_var', 'main_date', RubyLess::TypedString.new(v, :class => Time, :nil => could_be_nil))
out expand_with
end
Expand Down
12 changes: 6 additions & 6 deletions lib/zena/use/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def r_show(code = nil)
res = extract_label(res, @params, @params[:attr])

if @params[:blank] == 'hide'
"<% if !#{method}.blank? -%>#{@markup.wrap(res)}<% end -%>"
"<% if !#{method}.blank? %>#{@markup.wrap(res)}<% end %>"
else
res
end
Expand Down Expand Up @@ -523,16 +523,16 @@ def r_stylesheets
# Used by zafu templates that act as layouts (adminLayout for example) to insert the content if present
# or render.
def r_content_for_layout
"<% if content_for_layout = yield -%><%= content_for_layout %><% else -%>" +
"<% if content_for_layout = yield %><%= content_for_layout %><% else %>" +
expand_with +
"<% end -%>"
"<% end %>"
end

# Display the page's default title
def r_title_for_layout
"<% if @title_for_layout -%><%= @title_for_layout %><% elsif @node && !@node.new_record? -%><%= @node.title %><% elsif @node.parent -%><%= @node.parent.short_path %><% else -%>" +
"<% if @title_for_layout %><%= @title_for_layout %><% elsif @node && !@node.new_record? %><%= @node.title %><% elsif @node.parent %><%= @node.parent.short_path %><% else %>" +
expand_with +
"<% end -%>"
"<% end %>"
end

# Show html to add open a popup window to add a document.
Expand All @@ -542,7 +542,7 @@ def r_add_document
@markup.append_param(:class, 'btn_add')
node = self.node.list_context? ? self.node.up : self.node
res = node_action_link('add_doc', "<%= #{node}.zip %>", :text => text_for_link(''))
"<% if #{node}.can_write? -%>#{wrap(res)}<% end -%>"
"<% if #{node}.can_write? %>#{wrap(res)}<% end %>"
end

# Find icon through a relation named 'icon' or use first image child
Expand Down
6 changes: 3 additions & 3 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ def form_options
}

opts[:form_cancel] = %Q{
<% if #{node}.new_record? -%>
<% if #{node}.new_record? %>
<p class='btn_x'><a href='#' onclick='[\"<%= params[:dom_id] %>_add\", \"<%= params[:dom_id] %>_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p>
<% else -%>
<% else %>
<p class='btn_x'><%= link_to_remote(#{_('btn_x').inspect}, :url => #{node.form_name}_path(#{node}.zip) + \"/zafu?t_url=#{CGI.escape(template_url)}&dom_id=\#{params[:dom_id]}#{@context[:has_link_id] ? "&link_id=\#{#{node}.link_id}" : ''}\", :method => :get) %></p>
<% end -%>
<% end %>
}
end
else
Expand Down
21 changes: 19 additions & 2 deletions lib/zena/use/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'iconv'

module Zena
module Use
# On load this module changes ENV['LANG'] to 'C' in order to behave consitently without
Expand Down Expand Up @@ -258,6 +260,21 @@ def r_wrong_lang(params = @params)
end
end

def r_iconv
return parser_error("missing 'to' parameter") unless to = @params[:to]
begin
Iconv.iconv(to, 'utf8', 'éaïl')
rescue
return parser_error("invalid encoding #{to.inspect}")
end

data_name = get_var_name('iconv', 'data')
out "<% #{data_name} = capture do %>"
out expand_with
out "<% end %>"
out "<%= Iconv.iconv(#{to.inspect}, 'utf8', #{data_name}) %>"
end

def r_load
if dict = @params[:dictionary]
# FIXME: replace @options[:base_path] by @options[:skin_id]
Expand All @@ -274,7 +291,7 @@ def r_load
set_context_var('set_var', 'dictionary', RubyLess::TypedString.new(dict_name, :class => TranslationDict, :literal => dict, :dictionary_id => doc.id))

# Lazy loading (loads file on first request)
out "<% #{dict_name} = load_dictionary(#{doc.id}) -%>"
out "<% #{dict_name} = load_dictionary(#{doc.id}) %>"
else
return parser_error(dict.last_error)
end
Expand Down Expand Up @@ -342,7 +359,7 @@ def r_block
set_context_var('set_var', 'dictionary', @dict)

# Lazy loading (loads file on first request)
out "<% #{dict_name} = load_dictionary(#{@dict.opts[:dictionary_id]}) -%>"
out "<% #{dict_name} = load_dictionary(#{@dict.opts[:dictionary_id]}) %>"
end
super
else
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def node_context_vars(finder)
set_context_var('set_var', 'page_count', RubyLess::TypedString.new(page_count, Number))
set_context_var('set_var', 'count', RubyLess::TypedString.new(node_count, Number))

out "<% #{node_count} = Node.do_find(:count, #{query.to_s(:count)}); #{page_count} = (#{node_count} / #{query.page_size.to_f}).ceil; #{curr_page} = [1,params[:#{pagination_key}].to_i].max -%>"
out "<% #{node_count} = Node.do_find(:count, #{query.to_s(:count)}); #{page_count} = (#{node_count} / #{query.page_size.to_f}).ceil; #{curr_page} = [1,params[:#{pagination_key}].to_i].max %>"
elsif finder[:method].kind_of?(RubyLess::TypedString)
# Hash passed with :zafu => {} is inserted into context
sub_context.merge!(finder[:method].opts[:zafu] || {})
Expand Down
4 changes: 2 additions & 2 deletions lib/zena/use/recursion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def recursion_prepare
set_context_var('recursion', @name, {:proc_name => proc_name, :klass => klass})
depth = get_var_name('recursion', 'depth')
out "<% #{proc_name} = Proc.new do |#{depth}, #{var}| %>"
out "<% next if #{depth} > #{inc.params[:depth] ? [inc.params[:depth].to_i,30].min : 5} -%>"
@recursion_call = "<% end -%><% #{proc_name}.call(0,#{node}) %>"
out "<% next if #{depth} > #{inc.params[:depth] ? [inc.params[:depth].to_i,30].min : 5} %>"
@recursion_call = "<% end %><% #{proc_name}.call(0,#{node}) %>"
@context[:node] = node.move_to(var, node.klass)
@var = nil # avoid reuse of our 'var' as new var name
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def r_headers
if headers.empty?
out ""
else
out "<% set_headers(#{headers.join(', ')}) -%>"
out "<% set_headers(#{headers.join(', ')}) %>"
end
end
end # ZafuMethods
Expand Down
4 changes: 2 additions & 2 deletions lib/zena/use/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ module ZafuMethods
# node_count = get_var_name('paginate', 'nodes')
# page_count = get_var_name('paginate', 'count')
# curr_page = get_var_name('paginate', 'current')
# out "<% set_#{pagination_key}_count = (set_#{pagination_key}_nodes / @search_per_page).ceil; set_#{pagination_key} = [1,params[:page].to_i].max -%>"
# out "<% #{node_count} = @search_count; #{page_count} = (#{node_count} / @search_per_page).ceil; #{curr_page} = [1,params[:#{pagination_key}].to_i].max -%>"
# out "<% set_#{pagination_key}_count = (set_#{pagination_key}_nodes / @search_per_page).ceil; set_#{pagination_key} = [1,params[:page].to_i].max %>"
# out "<% #{node_count} = @search_count; #{page_count} = (#{node_count} / @search_per_page).ceil; #{curr_page} = [1,params[:#{pagination_key}].to_i].max %>"
# expand_if....
# end
end
Expand Down

0 comments on commit 311ddd1

Please sign in to comment.