Module: Handicraft::Helper
- Defined in:
- lib/handicraft/helper.rb
Defined Under Namespace
Classes: TagNode
Instance Method Summary collapse
- #breadcrumb(*crumb) ⇒ Object
- #handicraft_form_for(name, *args, &block) ⇒ Object
- #render_body_tag ⇒ Object
-
#render_list(list = [], options = {}) {|list| ... } ⇒ Object
.current will be added to current action, but if you want to add .current to another link, you can set @current = [‘/other_link’] TODO: hot about render_list( *args ).
- #render_page_title ⇒ Object
- #render_table(rows, renderrers, table_options = {}) ⇒ Object
- #s(html) ⇒ Object
- #yield_or_default(message, default_message = "") ⇒ Object
Instance Method Details
#breadcrumb(*crumb) ⇒ Object
21 22 23 24 25 |
# File 'lib/handicraft/helper.rb', line 21 def ( *crumb ) p = TagNode.new( :p, :class => "breadcrumb" ) p << crumb.join(' > ') return p.to_s end |
#handicraft_form_for(name, *args, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/handicraft/helper.rb', line 7 def handicraft_form_for(name, *args, &block) = args.last.is_a?(Hash) ? args.pop : {} = .merge(:builder => Handicraft::Form) if [:html] && [:html][:class].nil? [:html].merge!( :class => "form right-label" ) elsif [:html].nil? [:html] = { :class => "form right-label" } end args = (args << ) form_for(name, *args, &block) end |
#render_body_tag ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/handicraft/helper.rb', line 32 def render_body_tag class_attribute = ["#{controller_name}-controller","#{action_name}-action"].join(" ") id_attribute = (@body_id)? " id=\"#{@body_id}-page\"" : "" %Q|<!--[if lt IE 7 ]> <body class="#{class_attribute} ie6"><![endif]--> <!--[if gte IE 7 ]> <body class="#{class_attribute} ie"><![endif]--> <!--[if !IE]>--> <body#{id_attribute} class="#{class_attribute}"> <!--<![endif]-->| end |
#render_list(list = [], options = {}) {|list| ... } ⇒ Object
.current will be added to current action, but if you want to add .current to another link, you can set @current = [‘/other_link’] TODO: hot about render_list( *args )
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/handicraft/helper.rb', line 96 def render_list(list=[], ={}) if list.is_a? Hash = list list = [] end yield(list) if block_given? ul = TagNode.new('ul', :id => [:id], :class => [:class] ) list.each_with_index do |content, i| item_class = [] item_class << "first" if i == 0 item_class << "last" if i == (list.length - 1) item_content = content = {} if content.is_a? Array item_content = content[0] = content[1] end if [:class] item_class << [:class] end link = item_content.match(/href=(["'])(.*?)(\1)/)[2] rescue nil if ( link && current_page?(link) ) || ( @current && @current.include?(link) ) item_class << "current" end item_class = (item_class.empty?)? nil : item_class.join(" ") ul << li = TagNode.new('li', :class => item_class ) li << item_content end return ul.to_s end |
#render_page_title ⇒ Object
27 28 29 30 |
# File 'lib/handicraft/helper.rb', line 27 def render_page_title title = @page_title ? "#{SITE_NAME} | #{@page_title}" : SITE_NAME rescue "SITE_NAME" content_tag("title", title) end |
#render_table(rows, renderrers, table_options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/handicraft/helper.rb', line 49 def render_table(rows, renderrers, = {}) = { :has_header => true, :has_row_info => false, :id => nil, :class_name => "auto" }.merge() = [:id] ? { :id => [:id], :class => [:class_name] } : { :class => [:class_name] } table = TagNode.new('table', ) if [:has_header] == true table << thead = TagNode.new(:thead) thead << tr = TagNode.new(:tr, :class => 'odd') renderrers.each do |renderrer| tr << th = TagNode.new(:th) th << renderrer[0] end end table << tbody = TagNode.new('tbody') row_info = {} row_info[:total] = rows.length rows.each_with_index do |row,i| row_info[:current] = i tbody << tr = TagNode.new('tr', :class => cycle("","odd") ) renderrers.each do |renderrer| tr << td = TagNode.new('td') if renderrer[1].class == Proc if [:has_row_info] == true td << renderrer[1].call(row, row_info) else td << renderrer[1].call(row) end else td << renderrer[1] end end end return table.to_s end |
#s(html) ⇒ Object
45 46 47 |
# File 'lib/handicraft/helper.rb', line 45 def s(html) sanitize( html, :tags => %w(table thead tbody tr td th ol ul li div span font img sup sub br hr a pre p h1 h2 h3 h4 h5 h6), :attributes => %w(id class style src href size color) ) end |
#yield_or_default(message, default_message = "") ⇒ Object
3 4 5 |
# File 'lib/handicraft/helper.rb', line 3 def yield_or_default(, = "") .nil? ? : end |