Module: Useful::ErbHelpers::Tags

Includes:
Rack::Utils, Common
Defined in:
lib/useful/erb_helpers/tags.rb

Constant Summary

Constants included from Common

Common::OPTIONS

Instance Method Summary collapse

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(options={})
  options[:tag] ||= :div
  options[:style] ||= ''
  options[:style] = "clear:both;#{" #{options[:style]}" unless options[:style].blank?}"
  tag(options.delete(:tag), options) { '' }
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, options={}, &block)
  options[:tag] ||= :input
  options[:type] = type unless type.nil?
  unless name.nil?
    options[:name] = name 
    options[:id] ||= erb_helper_common_safe_id(name)
  end
  options[:value] = value unless value.nil?
  options[:disabled] = OPTIONS[:disabled] if options[:disabled]
  if block_given?
    tag(options.delete(:tag), options) { erb_helper_common_capture(&block) }
  else
    tag(options.delete(:tag), options)
  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, options={})
  "<#{name.to_s}#{" #{options.to_html_attrs}" unless options.empty?}#{block_given? ? ">#{yield}</#{name}" : " /"}>"
end