Module: Webs::Helper::Application

Defined in:
lib/helper/application.rb

Instance Method Summary collapse

Instance Method Details

#breaking_wrap(s, max_width = 5) ⇒ Object

Great for all browsers but opera, but doesn’t work in fw:sanitize



76
77
78
79
80
# File 'lib/helper/application.rb', line 76

def breaking_wrap( s, max_width=5 )
  return s if s.blank? || s.length < max_width
  r = Regexp.new( ".{1,#{max_width}}" )
  s.scan(r).join("<wbr>")
end

#cdata(str = "", &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/helper/application.rb', line 4

def cdata str="", &block
  return "<![CDATA[#{str}]]>" unless block
  
  content = capture(&block)
  begin
    # Rails 3
    output = ActiveSupport::SafeBuffer.new
    output.safe_concat("<![CDATA[")
    output << content
    output.safe_concat("]]>")
  rescue
    concat("<![CDATA[", block.binding)
    concat( content, block.binding)
    concat("]]>", block.binding)
  end
end

#html_breaking_wrap(html, col = 80) ⇒ Object

break text every col respecting tags



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/helper/application.rb', line 54

def html_breaking_wrap(html, col=80)
  # Breakup the string by html tags
  tag_regex = /<\/?[^>]*>/
  if html && html =~ tag_regex
    # Breakup the string by html tags
    ss = StringScanner.new( html )
    a = []
    while ( ss.scan_until(tag_regex) )
      a << ss.pre_match if !ss.pre_match.blank?
      a << ss.matched 
      ss = StringScanner.new( ss.rest ) 
    end
    a << ss.rest if ss.rest?
    
    # For each non-tag break long words
    a.collect{ |s| s[0..0]=='<' ? s : text_breaking_wrap(s, col) }.join
  else
    text_breaking_wrap(html, col) 
  end
end

#text_breaking_wrap(txt, col = 80) ⇒ Object

break text every col



48
49
50
51
# File 'lib/helper/application.rb', line 48

def text_breaking_wrap(txt, col = 80)
  return nil if txt.blank?
  txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3 ")
end

#webs_infoObject

shouldn’t need this anymore for Rails 3, just use image_tag def webs_image_url img

"http://#{Webs::ASSET_HOST}/images/#{img}"

end



26
27
28
# File 'lib/helper/application.rb', line 26

def webs_info
  render :partial=>'shared/webs_info'
end

#webs_page_settings(options = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/helper/application.rb', line 39

def webs_page_settings options = {}
  options.keys.each do |k| 
    val = options[k]
    val = h(val)
    self.instance_variable_set("@#{k.to_s}".to_sym, val) 
  end
end

#webs_permission_level_select_options(levels = Webs::PERMISSION_LEVELS, names = {}) ⇒ Object

return an array of value, name select options for the given levels if names are present map the names by level key



32
33
34
35
36
37
# File 'lib/helper/application.rb', line 32

def webs_permission_level_select_options levels=Webs::PERMISSION_LEVELS, names={}
  levels.collect do |lvl_key|
    lvl = PERMISSION_LEVEL[lvl_key]
    [ lvl[:value], names[lvl_key] || lvl[:name] ]
  end
end