Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/paolodona/rails-widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Wilcox committed Mar 21, 2009
2 parents 6a39377 + 3f70462 commit d24ef02
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/widgets/code_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CodeHelper
# es: <%= code 'models/post.rb' %>
def code file_path, opts = {}
html = ''
if opts[:generate_css] == true
if (opts.has_key?[:generate_css] && opts[:generate_css] != false) || opts[:generate_css] == true
css_template = ERB.new IO.read(File.expand_path(File.dirname(__FILE__) + '/code.css.erb'))
html << css_template.result(binding)
end
Expand Down
24 changes: 10 additions & 14 deletions lib/widgets/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ def render_navigation(name=:main, opts={}, &proc)
raise ArgumentError, "Missing name parameter in render_navigation call" unless name
raise ArgumentError, "Missing block in render_navigation call" unless block_given?
@_navigation = Navigation.new(name, opts)
@_binding = proc.binding # the binding of calling page
instance_eval(&proc)
out @_navigation.render_css('navigation') if @_navigation.generate_css?
out tag('div',@_navigation.html ,true)
concat @_navigation.render_css('navigation') if @_navigation.generate_css?
concat tag('div',@_navigation.html ,true)
render_navigation_items
out '</div>'
concat '</div>'
nil
end

Expand All @@ -31,28 +30,25 @@ def add_item opts = {}, &block
def render_navigation_items
return if @_navigation.items.empty?

out "<ul>\n"
concat "<ul>\n"
@_navigation.items.each_with_index do |item,index|
if item.disabled?
item.html[:class] = 'disabled'
elsif item.highlighted?(params)
item.html[:class] = 'active'
end

out '<li>'
concat '<li>'
if item.disabled?
out content_tag('span', item.name, item.html)
concat content_tag('span', item.name, item.html)
else
out link_to(item.name, item.link, item.html)
concat link_to(item.name, item.link, item.html)
end
out @_navigation.separator unless index == @_navigation.items.size - 1
out "</li>\n"
concat @_navigation.separator unless index == @_navigation.items.size - 1
concat "</li>\n"
end
out '</ul>'
concat '</ul>'
end

def out(string); concat string, @_binding; end

end
end

2 changes: 1 addition & 1 deletion lib/widgets/spiffy_corners/spiffy_corners_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def spiffy_corners opts={}, &block
@_spiffy_corners_content = capture(&block)
html << rw_render_template('spiffy_corners/spiffy5', binding)

concat(html.join, block.binding)
concat html.join
return nil
end
end
Expand Down
25 changes: 11 additions & 14 deletions lib/widgets/tabnav_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def tabnav name, opts={}, &block
html << tag('div', options, true)
html << capture(&block)
html << '</div>'
concat( html, block.binding)
concat html
nil # avoid duplication if called with <%= %>
else
return html
Expand All @@ -39,14 +39,13 @@ def render_tabnav(name, opts={}, &proc)
raise ArgumentError, "Missing name parameter in tabnav call" unless name
raise ArgumentError, "Missing block in tabnav call" unless block_given?
@_tabnav = Tabnav.new(name, opts)
@_binding = proc.binding # the binding of calling page

instance_eval(&proc)
out @_tabnav.render_css('tabnav') if @_tabnav.generate_css?
out tag('div',@_tabnav.html ,true)
concat @_tabnav.render_css('tabnav') if @_tabnav.generate_css?
concat tag('div',@_tabnav.html ,true)
@_tabnav.sort! if opts[:sort] == true
render_tabnav_tabs
out "</div>\n"
concat "</div>\n"
nil
end

Expand All @@ -69,7 +68,7 @@ def controller_names
def render_tabnav_tabs
return if @_tabnav.tabs.empty?

out tag('ul', {} , true)
concat tag('ul', {} , true)

@_tabnav.tabs.each do |tab|
li_options = {}
Expand All @@ -84,11 +83,11 @@ def render_tabnav_tabs
end
li_options[:class] = tab_html[:class]

out tag('li', li_options, true)
concat tag('li', li_options, true)
if tab.disabled? || (tab.link.empty? && tab.remote_link.nil?)
out content_tag('span', tab.name, tab_html)
concat content_tag('span', tab.name, tab_html)
elsif !tab.link.empty?
out link_to(tab.name, tab.link, tab_html)
concat link_to(tab.name, tab.link, tab_html)
elsif tab.remote_link
success = "document.getElementsByClassName('active', $('" + @_tabnav.html[:id]+ "')).each(function(item){item.removeClassName('active');});"
success += "$('#{tab.html[:id]}').addClassName('active');"
Expand All @@ -100,17 +99,15 @@ def render_tabnav_tabs
:loading => loading_function + success,
:loaded => "$('#{@_tabnav.html[:id]}_content').setStyle({height: 'auto'});"
}
out link_to_remote(tab.name, remote_opts.merge(tab.remote_link), tab_html)
concat link_to_remote(tab.name, remote_opts.merge(tab.remote_link), tab_html)
else
raise "WHAT THE HELL?"
end
out "</li>\n"
concat "</li>\n"
end
out '</ul>'
concat '</ul>'
end

def out(string); concat string, @_binding; end

# generate javascript function to use
# while loading remote tabs
# NB: EXPERIMENTAL
Expand Down

0 comments on commit d24ef02

Please sign in to comment.