simple_helpers 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad5106d5e8ba4e9bb0e42eef4e4a105734d9933f
4
- data.tar.gz: 095713110ea60c96ec9d0fa8eea86b73ce323021
3
+ metadata.gz: 75600df7a0ae09aa8c1b237125e570b7f2ed9d85
4
+ data.tar.gz: 09011776669374e42cb13f8be960c804b1e83901
5
5
  SHA512:
6
- metadata.gz: 4fa4003a2dd23424a253b7c160e85142dd2bb6bff361bd6fc065ee40e6509e07e89205f652e7a5613df3be6fd6c3008b7da9572b37abb3d5f83a1ed6a0450ea8
7
- data.tar.gz: aa0a33dece45792fa98a62137c181848aee560be67b5a7e35dbe9d712b1cbc27afe8b0100c9ed5a73904a58a3ebc7045a3486ad3025093c640cfa3759c348088
6
+ metadata.gz: 836d425d56ecb1d515164c81c4715bf29521070350c3902a7d1dd3a53256328ff1ae50179e2fe019d7f21e5cd47041c8f5cee881597d401ec311049ff5739806
7
+ data.tar.gz: 4400234e48e51e905ff601a66566bebeee24fcef2cba71101d80245d2d2a7dcb2734b3bfc4c58188761be4fcb29857eacbfa6d47c568d2008d19a21d4797c2ab
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
data/README.md CHANGED
@@ -45,7 +45,7 @@ require "simple_helpers"
45
45
 
46
46
  SimpleHelpers.configure do |config|
47
47
  config.helpers = {
48
- page_title: { prefix: "MyBlog" } # other options: suffix, separator
48
+ page_title: { suffix: "MyBlog", separator: " · " } # other option: prefix
49
49
  }
50
50
  end
51
51
  ```
@@ -1,6 +1,6 @@
1
1
  module SimpleHelpers
2
2
  class Config
3
- DEFAULT_SEPARATOR = " · "
3
+ DEFAULT_SEPARATOR = " - "
4
4
 
5
5
  def self.helpers
6
6
  @helpers ||= {}
@@ -5,6 +5,29 @@ module SimpleHelpers
5
5
  array.collect{|item| item.to_s}
6
6
  end
7
7
 
8
+ def self.create_method(controller, name)
9
+ controller.class_eval do
10
+ define_method(name) do |*args|
11
+ if args.empty?
12
+ send "#{name}_get"
13
+ else
14
+ send "#{name}_set", args.first
15
+ end
16
+ end
17
+
18
+ define_method("#{name}_set") do |*args|
19
+ instance_variable_set "@#{name}", args.first
20
+ end
21
+
22
+ define_method("#{name}_get") do |*args|
23
+ "%{prefix}%{prefix_separator}%{content}%{suffix_separator}%{suffix}" %
24
+ SimpleHelpers::Support.simple_helper_parts(controller, name)
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
8
31
  def self.scopes(controller, method_name)
9
32
  controller_name = controller.class.name.underscore
10
33
  controller_name.gsub!(/\//, "_")
@@ -24,12 +47,12 @@ module SimpleHelpers
24
47
  }
25
48
  end
26
49
 
27
- def self.parser(controller, context)
28
- entries(context).each do |key|
50
+ def self.replace_tags(controller, context)
51
+ tags(context).each do |tag|
29
52
  begin
30
- value = simple_helper_value(controller, key)
53
+ value = simple_helper_value(controller, tag)
31
54
  ensure
32
- context.sub!(key, value)
55
+ context.sub!(tag, value)
33
56
  end
34
57
  end
35
58
  context
@@ -44,7 +67,7 @@ module SimpleHelpers
44
67
  end
45
68
  end
46
69
 
47
- def self.get_i18n_content(controller, key, options)
70
+ def self.get_text_from_locale(controller, key, options)
48
71
  scopes = SimpleHelpers::Support.scopes(controller, key)
49
72
 
50
73
  result = SimpleHelpers::Support.translate(scopes[:first], options)
@@ -54,43 +77,20 @@ module SimpleHelpers
54
77
  result
55
78
  end
56
79
 
57
- def self.create_method(controller, name)
58
- controller.class_eval do
59
- define_method(name) do |*args|
60
- if args.empty?
61
- send "#{name}_get"
62
- else
63
- send "#{name}_set", args.first
64
- end
65
- end
66
-
67
- define_method("#{name}_set") do |*args|
68
- instance_variable_set "@#{name}", args.first
69
- end
70
-
71
- define_method("#{name}_get") do |*args|
72
- "%{prefix}%{prefix_separator}%{content}%{suffix_separator}%{suffix}" %
73
- SimpleHelpers::Support.simple_helper_parts(controller, name)
74
- end
75
- end
76
- end
77
-
78
- private
79
-
80
- def self.entries(context)
80
+ def self.tags(context)
81
81
  context.scan(/{{.*?}}/i)
82
82
  end
83
83
 
84
84
  def self.simple_helper_value(controller, key)
85
85
  tag = key.delete("{}")
86
86
  if tag.start_with? "@"
87
- get_instance_variable(controller, tag)
87
+ get_from_instance_variable(controller, tag)
88
88
  else
89
89
  get_from_controller(controller, tag)
90
90
  end || ""
91
91
  end
92
92
 
93
- def self.get_instance_variable(controller, key)
93
+ def self.get_from_instance_variable(controller, key)
94
94
  parts = key.split(".")
95
95
  first_argument = parts.shift
96
96
  instance_variable = controller.instance_variable_get(first_argument)
@@ -109,8 +109,8 @@ module SimpleHelpers
109
109
 
110
110
  def self.simple_helper_parts(controller, name)
111
111
  name_options = controller.instance_variable_get("@#{name}_options") || {}
112
- text_raw = SimpleHelpers::Support.get_i18n_content(controller, name, name_options)
113
- content = SimpleHelpers::Support.parser(controller, text_raw)
112
+ text_raw = SimpleHelpers::Support.get_text_from_locale(controller, name, name_options)
113
+ content = SimpleHelpers::Support.replace_tags(controller, text_raw)
114
114
 
115
115
  helper_options = SimpleHelpers::Config.helpers[name.to_sym].merge(name_options)
116
116
  prefix = helper_options.fetch(:prefix, "")
@@ -2,7 +2,7 @@ module SimpleHelpers
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -3,6 +3,6 @@ require "simple_helpers"
3
3
  SimpleHelpers.configure do |config|
4
4
  # Helper methods that will be automatically created in the controllers
5
5
  # config.helpers = {
6
- # page_title: { prefix: "MySite", separator: " - " }
6
+ # page_title: { prefix: "MySite" }
7
7
  # }
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitor Oliveira