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

error_messages_for

public error_messages_for(model_instance)

Meta Tags

Parameters:

Since:

0.0.2

[View source]


35
36
37
38
39
40
# File 'lib/rango/helpers/general.rb', line 35

def error_messages_for(model_instance)
  tag :ul do
    messages = model_instance.errors.full_messages
    messages.map { |message| tag :li, message }
  end
end

javascript

public javascript(basename)

stolen from pupu (but it’s OK, it’s my code)

Meta Tags

Parameters:

Since:

0.0.2

[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)

Meta Tags

Parameters:

Since:

0.0.2

[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

link_to

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)

Meta Tags

Parameters:

Since:

0.0.1

[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)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


17
18
19
# File 'lib/rango/helpers/syntax.rb', line 17

def maruku(text, options = Hash.new)
  require "maruku"
end

stylesheet

public stylesheet(basename, attrs = Hash.new)

Meta Tags

Parameters:

Since:

0.0.2

[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)

Meta Tags

Parameters:

Since:

0.0.2

[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)

Meta Tags

Parameters:

Since:

0.0.1

[View source]


22
23
24
25
26
# File 'lib/rango/helpers/syntax.rb', line 22

def syntax(text, options = Hash.new)
  require "syntax/convertors/html"
  convertor = Syntax::Convertors::HTML.for_syntax(options[:language] || "ruby")
  convertor.convert(text, false)
end

textile

public textile(text)

Meta Tags

Parameters:

Since:

0.0.1

[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)
  options = args.extract_options!
  unless args.empty?
    options[:size]     = args[0] || 75
    options[:omission] = args[1] || "..."
  end
  options.reverse_merge!(:size => 75, :omission => "...")
  text.scan(/(\S+)(\s+)/)[0..options[:size]].flatten.join << options[:omission] if text
end