Module: Tenjin::HtmlTagHelper

Included in:
Context
Defined in:
lib/tenjin.rb

Overview

helper module for html tags. depends on HtmlHelper and SafeHelper.

Defined Under Namespace

Classes: Cycle

Class Method Summary collapse

Class Method Details

._hash2attr(hash) ⇒ Object

:nodoc:



139
140
141
142
143
144
145
146
# File 'lib/tenjin.rb', line 139

def _hash2attr(hash)  # :nodoc:
  attr = ""
  return attr unless hash
  hash.each_pair do |k, v|
    attr << " #{safe_escape(k.to_s)}=\"#{safe_escape(v.to_s)}\""
  end
  return attr
end

.checked(expr) ⇒ Object

return ‘ checked=“checked”’ if expr is not false or nil



109
110
111
# File 'lib/tenjin.rb', line 109

def checked(expr)
  return expr ? safe_str(' checked="checked"') : ''
end

.disabled(expr) ⇒ Object

return ‘ disabled=“disabled”’ if expr is not false or nil



119
120
121
# File 'lib/tenjin.rb', line 119

def disabled(expr)
  return expr ? safe_str(' disabled="disabled"') : ''
end

return ‘<a href=“” onclick=“js_code;return”>label</a>’.



135
136
137
# File 'lib/tenjin.rb', line 135

def js_link(label, js_code, tags=nil)
  return safe_str(%Q`<a href="javascript:undefined" onclick="#{safe_escape(js_code.to_s)};return false"#{_hash2attr(tags)}>#{safe_escape(label.to_s)}</a>`)
end

.new_cycle(*values) ⇒ Object



182
183
184
# File 'lib/tenjin.rb', line 182

def new_cycle(*values)
  return Cycle.new(*values)
end

.nl2br(text) ⇒ Object

convert “n” into “<br />n”



150
151
152
# File 'lib/tenjin.rb', line 150

def nl2br(text)
  return safe_str(text.to_s.gsub(/\n/, "<br />\n"))
end

.nv(name, value, separator = nil) ⇒ Object

(experimental) return ‘ name=“name” value=“value”’ string. if separator specified then id attribute is also added.



125
126
127
128
129
130
131
132
# File 'lib/tenjin.rb', line 125

def nv(name, value, separator=nil)
  nattr = safe_escape(name.to_s)
  vattr = safe_escape(value.to_s)
  s = separator \
    ? " name=\"#{nattr}\" value=\"#{vattr}\" id=\"#{nattr}#{separator}#{vattr}\"" \
    : " name=\"#{nattr}\" value=\"#{vattr}\""
  return safe_str(s)
end

.selected(expr) ⇒ Object

return ‘ selected=“selected”’ if expr is not false or nil



114
115
116
# File 'lib/tenjin.rb', line 114

def selected(expr)
  return expr ? safe_str(' selected="selected"') : ''
end

.tagattr(name, expr, value = nil, escape = true) ⇒ Object

(experimental) return ‘ name=“value”’ if expr is not false nor nil. if value is nil or false then expr is used as value.



98
99
100
101
102
103
104
105
106
# File 'lib/tenjin.rb', line 98

def tagattr(name, expr, value=nil, escape=true)
  if !expr
    return ''
  elsif escape
    return safe_str(" #{name}=\"#{safe_escape((value || expr).to_s)}\"")
  else
    return safe_str(" #{name}=\"#{value || expr}\"")
  end
end

.text2html(text) ⇒ Object

convert “n” and “ ” into “<br />n” and “ &nbsp;”



155
156
157
# File 'lib/tenjin.rb', line 155

def text2html(text)
  return nl2br(safe_escape(text.to_s).gsub(/  /, ' &nbsp;'))
end