Module: Curtain::HTMLHelpers
- Included in:
- FormBuilder
- Defined in:
- lib/curtain/html_helpers.rb
Constant Summary collapse
- VOID_TAGS =
[ :br, :hr, :img ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(attrs={}) void_tag(#{tag.inspect}, attrs) end METHOD end
- CONTENT_TAGS =
[ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end
Instance Method Summary collapse
-
#a(content = nil, attrs = {}, &body) ⇒ String
HTML a tag.
-
#b(content = nil, attrs = {}, &body) ⇒ String
HTML b tag.
-
#br(attrs = {}) ⇒ String
HTML br tag.
- #capture ⇒ Object
-
#content_tag(name, content = nil, attrs = {}, &body) ⇒ String
Generates a with opening and closing tags and potentially content.
-
#dd(content = nil, attrs = {}, &body) ⇒ String
HTML dd tag.
-
#div(content = nil, attrs = {}, &body) ⇒ String
HTML div tag.
-
#dl(content = nil, attrs = {}, &body) ⇒ String
HTML dl tag.
-
#dt(content = nil, attrs = {}, &body) ⇒ String
HTML dt tag.
-
#h1(content = nil, attrs = {}, &body) ⇒ String
HTML h1 tag.
-
#h2(content = nil, attrs = {}, &body) ⇒ String
HTML h2 tag.
-
#h3(content = nil, attrs = {}, &body) ⇒ String
HTML h3 tag.
-
#h4(content = nil, attrs = {}, &body) ⇒ String
HTML h4 tag.
-
#h5(content = nil, attrs = {}, &body) ⇒ String
HTML h5 tag.
-
#h6(content = nil, attrs = {}, &body) ⇒ String
HTML h6 tag.
- #hr(attrs = {}) ⇒ Object
-
#i(content = nil, attrs = {}, &body) ⇒ String
HTML i tag.
- #img(attrs = {}) ⇒ Object
-
#p(content = nil, attrs = {}, &body) ⇒ String
HTML p tag.
-
#table(content = nil, attrs = {}, &body) ⇒ String
HTML table tag.
-
#tbody(content = nil, attrs = {}, &body) ⇒ String
HTML tbody tag.
-
#td(content = nil, attrs = {}, &body) ⇒ String
HTML td tag.
-
#tfoot(content = nil, attrs = {}, &body) ⇒ String
HTML tfoot tag.
-
#th(content = nil, attrs = {}, &body) ⇒ String
HTML th tag.
-
#thead(content = nil, attrs = {}, &body) ⇒ String
HTML thead tag.
-
#tr(content = nil, attrs = {}, &body) ⇒ String
HTML tr tag#.
-
#void_tag(name, attrs = {}) ⇒ String
Generates a tag that has no content.
Instance Method Details
#a(content = nil, attrs = {}, &body) ⇒ String
Returns HTML a tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#b(content = nil, attrs = {}, &body) ⇒ String
Returns HTML b tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#br(attrs = {}) ⇒ String
Returns HTML br tag.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/curtain/html_helpers.rb', line 73 VOID_TAGS = [ :br, :hr, :img ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(attrs={}) void_tag(#{tag.inspect}, attrs) end METHOD end |
#capture ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/curtain/html_helpers.rb', line 3 def capture original_buffer = @output_buffer @output_buffer = Curtain::OutputBuffer.new yield ensure @output_buffer = original_buffer end |
#content_tag(name, content = nil, attrs = {}, &body) ⇒ String
Generates a with opening and closing tags and potentially content.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/curtain/html_helpers.rb', line 50 def content_tag(name, content=nil, attrs={}, &body) if content.is_a?(Hash) attrs = content content = nil end if block_given? content = capture(&body) end tag = tag_opening(name, attrs) tag << ">".html_safe tag << content tag << "</#{name}>".html_safe end |
#dd(content = nil, attrs = {}, &body) ⇒ String
Returns HTML dd tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#div(content = nil, attrs = {}, &body) ⇒ String
Returns HTML div tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#dl(content = nil, attrs = {}, &body) ⇒ String
Returns HTML dl tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#dt(content = nil, attrs = {}, &body) ⇒ String
Returns HTML dt tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#h1(content = nil, attrs = {}, &body) ⇒ String
Returns HTML h1 tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#h2(content = nil, attrs = {}, &body) ⇒ String
Returns HTML h2 tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#h3(content = nil, attrs = {}, &body) ⇒ String
Returns HTML h3 tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#h4(content = nil, attrs = {}, &body) ⇒ String
Returns HTML h4 tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#h5(content = nil, attrs = {}, &body) ⇒ String
Returns HTML h5 tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#h6(content = nil, attrs = {}, &body) ⇒ String
Returns HTML h6 tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#hr(attrs = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/curtain/html_helpers.rb', line 73 VOID_TAGS = [ :br, :hr, :img ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(attrs={}) void_tag(#{tag.inspect}, attrs) end METHOD end |
#i(content = nil, attrs = {}, &body) ⇒ String
Returns HTML i tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#img(attrs = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/curtain/html_helpers.rb', line 73 VOID_TAGS = [ :br, :hr, :img ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(attrs={}) void_tag(#{tag.inspect}, attrs) end METHOD end |
#p(content = nil, attrs = {}, &body) ⇒ String
Returns HTML p tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#table(content = nil, attrs = {}, &body) ⇒ String
Returns HTML table tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#tbody(content = nil, attrs = {}, &body) ⇒ String
Returns HTML tbody tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#td(content = nil, attrs = {}, &body) ⇒ String
Returns HTML td tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#tfoot(content = nil, attrs = {}, &body) ⇒ String
Returns HTML tfoot tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#th(content = nil, attrs = {}, &body) ⇒ String
Returns HTML th tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#thead(content = nil, attrs = {}, &body) ⇒ String
Returns HTML thead tag.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#tr(content = nil, attrs = {}, &body) ⇒ String
Returns HTML tr tag#.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/curtain/html_helpers.rb', line 127 CONTENT_TAGS = [ :a, :b, :dd, :div, :dl, :dt, :h1, :h2, :h3, :h4, :h5, :h6, :i, :li, :option, :p, :section, :table, :tbody, :td, :tfoot, :th, :thead, :tr, :ul ].each do |tag| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{tag}(content=nil, attrs={}, &body) content_tag(#{tag.inspect}, content, attrs, &body) end METHOD end |
#void_tag(name, attrs = {}) ⇒ String
Generates a tag that has no content.
24 25 26 |
# File 'lib/curtain/html_helpers.rb', line 24 def void_tag(name, attrs={}) tag_opening(name, attrs) << ">".html_safe end |