Module: Useful::ErbHelpers::Tags
- Includes:
- Rack::Utils, Common
- Defined in:
- lib/useful/erb_helpers/tags.rb
Constant Summary
Constants included from Common
Instance Method Summary collapse
- #clear_tag(options = {}) ⇒ Object
-
#h_text(text, opts = {}) ⇒ Object
escape tag text content and format for text-like display.
- #input_tag(type, name, value = nil, options = {}, &block) ⇒ Object
-
#tag(name, options = {}) ⇒ Object
emulator for rails’ ‘content_tag’ EX : tag(:h1, :title => “shizam”) { “shizam” } => <h1 title=“shizam”>shizam</h1>.
Methods included from Common
#erb_helper_clear_output_buffer
Instance Method Details
#clear_tag(options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/useful/erb_helpers/tags.rb', line 16 def clear_tag(={}) [:tag] ||= :div [:style] ||= '' [:style] = "clear:both;#{" #{[:style]}" unless [:style].blank?}" tag(.delete(:tag), ) { '' } end |
#h_text(text, opts = {}) ⇒ Object
escape tag text content and format for text-like display
30 31 32 33 34 35 36 37 |
# File 'lib/useful/erb_helpers/tags.rb', line 30 def h_text(text, opts={}) h(text.to_s). gsub(/\r\n?/, "\n"). # \r\n and \r -> \n split("\n").collect do |line| line.nil? ? '': line.sub(/(\s+)?\S*/) {|lead| lead.gsub(/\s/,' ')} end.join("\n"). # change any leading white spaces on a line to ' ' gsub(/\n/,'\1<br />') # newlines -> br added end |
#input_tag(type, name, value = nil, options = {}, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/useful/erb_helpers/tags.rb', line 40 def input_tag(type, name, value=nil, ={}, &block) [:tag] ||= :input [:type] = type unless type.nil? unless name.nil? [:name] = name [:id] ||= erb_helper_common_safe_id(name) end [:value] = value unless value.nil? [:disabled] = OPTIONS[:disabled] if [:disabled] if block_given? tag(.delete(:tag), ) { erb_helper_common_capture(&block) } else tag(.delete(:tag), ) end end |
#tag(name, options = {}) ⇒ Object
emulator for rails’ ‘content_tag’ EX : tag(:h1, :title => “shizam”) { “shizam” }
> <h1 title=“shizam”>shizam</h1>
59 60 61 |
# File 'lib/useful/erb_helpers/tags.rb', line 59 def tag(name, ={}) "<#{name.to_s}#{" #{.to_html_attrs}" unless .empty?}#{block_given? ? ">#{yield}</#{name}" : " /"}>" end |