/
it.rb
45 lines (40 loc) · 1.53 KB
/
it.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'it/parser'
require 'it/interpolation'
require 'it/tag'
require 'it/link'
require 'it/plain'
require 'it/helper'
ActiveSupport.on_load(:action_view) do
include It::Helper
end
# Namespace of the gem.
module It
# It outside of your views. See documentation at Helper#it
def self.it(identifier, options = {})
options.stringify_keys!
Parser.new(I18n.t(identifier, locale: (options["locale"] || I18n.locale)), options).process
end
# Creates a new link to be used in +it+.
#
# * +href+: The url for the link. You may specify it as a String or as a named route like +article_path+. It's not possible to specify
# a Hash like <code>{controller: "articles", action: "index"}</code> directly. Use the +url_for+ helper, if you would like to specify your
# links like that.
# * +options+: The options as an Hash. Use them like you would with +link_to+. <em>(optional)</em>
def self.link(href, options = {})
It::Link.new(href, options)
end
# Creates a new plain replacement to be used in +it+.
#
# * +template+: A string to be used as the template. An example would be <code>"%s[http://www.rubyonrails.org]"</code>. Defaults to
# <code>"%s"</code>. <em>(optional)</em>
def self.plain(template = "%s")
It::Plain.new(template)
end
# Creates a new tag to be used in +it+.
#
# * +tag_name+: The name of the tag as a Symbol or String.
# * +options+: The options will become attributes on the tag. <em>(optional)</em>
def self.tag(tag_name, options = {})
It::Tag.new(tag_name, options)
end
end