Module: Rango::Helpers
Public Visibility
Public Class Method Summary
load | |
---|---|
load_helpers(helpers = @@helpers_files) |
Load only specific helpers instead of loading all the helpers. |
Public Instance Method Summary
#copyright(from) | |
---|---|
#error_messages_for(model_instance) | |
#javascript(basename) |
stolen from pupu (but it’s OK, it’s my code). |
#javascripts(*names) | |
#link_item(name, url) | |
#link_to(name, url, options = Hash.new) | |
#mail_to(mail, text = mail) | |
#markdown(text) | |
#maruku(text, options = Hash.new) | |
#stylesheet(basename, attrs = Hash.new) | |
#stylesheets(*names) | |
#syntax(text, options = Hash.new) | |
#textile(text) | |
#truncate(text, *args) |
Public Class Method Details
load
public
load
[View source]
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rango/helpers/merb-helpers.rb', line 8 def self.load require @@helpers_dir + '/core_ext' require @@helpers_dir + '/core_ext/numeric' # if Rango::Plugins.config[:merb_helpers] # config = Rango::Plugins.config[:merb_helpers] # # if config[:include] && !config[:include].empty? # load_helpers(config[:include]) # else # # This is in case someone defines an entry in the config, # # but doesn't put in a with or without option # load_helpers # end # # else load_helpers # end end |
load_helpers
public
load_helpers(helpers = @@helpers_files)
Load only specific helpers instead of loading all the helpers
[View source]
29 30 31 |
# File 'lib/rango/helpers/merb-helpers.rb', line 29 def self.load_helpers(helpers = @@helpers_files) helpers.each {|helper| Kernel.load(File.join(@@helpers_dir, "#{helper}.rb") )} # using load here allows specs to work end |
Public Instance Method Details
copyright
public
copyright(from)
[View source]
8 9 10 11 |
# File 'lib/rango/helpers/general.rb', line 8 def copyright(from) now = Time.now.year now.eql?(from) ? now : "#{from} - #{now}" end |
error_messages_for
public
error_messages_for(model_instance)
[View source]
35 36 37 38 39 40 |
# File 'lib/rango/helpers/general.rb', line 35 def (model_instance) tag :ul do = model_instance.errors. .map { || tag :li, } end end |
javascript
public
javascript(basename)
stolen from pupu (but it’s OK, it’s my code)
[View source]
7 8 9 10 |
# File 'lib/rango/helpers/assets.rb', line 7 def javascript(basename) path = Path.new(File.join(Project.settings.media_root, "javascripts", "#{basename}.js")) tag :script, src: path.url, type: "text/javascript" end |
javascripts
public
javascripts(*names)
[View source]
20 21 22 |
# File 'lib/rango/helpers/assets.rb', line 20 def javascripts(*names) names.map { |name| self.javascript(name) }.join("\n") end |
link_item
public
link_item(name, url)
[View source]
20 21 22 |
# File 'lib/rango/helpers/general.rb', line 20 def link_item(name, url) tag :li, link_to(name, url) end |
link_to
public
link_to(name, url, options = Hash.new)
[View source]
14 15 16 17 |
# File 'lib/rango/helpers/general.rb', line 14 def link_to(name, url, = Hash.new) default = {href: URI.escape(url), title: name.to_s.gsub(/'/, ''')} tag :a, name, default.merge() end |
mail_to
public
mail_to(mail, text = mail)
[View source]
29 30 31 32 |
# File 'lib/rango/helpers/general.rb', line 29 def mail_to(mail, text = mail) mail.gsub!("@" "@") tag :a, text, href: "mailto:#{mail}" end |
markdown
public
markdown(text)
[View source]
12 13 14 |
# File 'lib/rango/helpers/syntax.rb', line 12 def markdown(text) require "bluecloth" end |
maruku
public
maruku(text, options = Hash.new)
[View source]
17 18 19 |
# File 'lib/rango/helpers/syntax.rb', line 17 def maruku(text, = Hash.new) require "maruku" end |
stylesheet
public
stylesheet(basename, attrs = Hash.new)
[View source]
13 14 15 16 17 |
# File 'lib/rango/helpers/assets.rb', line 13 def stylesheet(basename, attrs = Hash.new) path = Path.new(File.join(Project.settings.media_root, basename)) default = {href: path.url, media: 'screen', rel: 'stylesheet', type: 'text/css'} single_tag :link, default.merge(attrs) end |
stylesheets
public
stylesheets(*names)
[View source]
25 26 27 |
# File 'lib/rango/helpers/assets.rb', line 25 def stylesheets(*names) names.map { |name| self.stylesheet(name) }.join("\n") end |
syntax
public
syntax(text, options = Hash.new)
[View source]
22 23 24 25 26 |
# File 'lib/rango/helpers/syntax.rb', line 22 def syntax(text, = Hash.new) require "syntax/convertors/html" convertor = Syntax::Convertors::HTML.for_syntax([:language] || "ruby") convertor.convert(text, false) end |
textile
public
textile(text)
[View source]
6 7 8 9 |
# File 'lib/rango/helpers/syntax.rb', line 6 def textile(text) require "redcloth" RedCloth.new(text).to_html end |
truncate
public
truncate(text, *args)
[View source]
42 43 44 45 46 47 48 49 50 |
# File 'lib/rango/helpers/general.rb', line 42 def truncate(text, *args) = args. unless args.empty? [:size] = args[0] || 75 [:omission] = args[1] || "..." end .reverse_merge!(:size => 75, :omission => "...") text.scan(/(\S+)(\s+)/)[0..[:size]].flatten.join << [:omission] if text end |