simple_helpers 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,2 +1,3 @@
1
+ language: ruby
1
2
  rvm:
2
3
  - 1.9.3
data/README.md CHANGED
@@ -1,16 +1,46 @@
1
1
  # Simple Helpers
2
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/vitormil/simple_helpers)
3
+ [![Build Status](https://secure.travis-ci.org/vitormil/simple_helpers.png)](http://travis-ci.org/vitormil/simple_helpers)
2
4
 
3
5
  Easily create variables with I18n and interpolation support to your controllers and views.
4
6
 
5
7
  You can configure it to automaticly create some methods (like page_title, page_subtitle) or call the method **simple_helper** manually according to your needs.
6
8
 
7
- Examples:
8
-
9
9
  To display page title in your view:
10
10
 
11
- **<%= page_title %>**
11
+ ```ruby
12
+ <%= page_title %>
13
+ ```
14
+
15
+ ### Usage
16
+
17
+ You can configure an automatic behavior to your controllers setting an initializer:
18
+
19
+ ```ruby
20
+ require "simple_helpers"
21
+
22
+ SimpleHelpers.configure do |config|
23
+ config.helpers = [:page_title]
24
+ config.blacklist = [SessionsController]
25
+ config.whitelist = []
26
+ end
27
+ ```
28
+
29
+ And/or call the method **simple_helper** manually according to your needs:
30
+
31
+ ```ruby
32
+ # some examples
33
+ simple_helper :page_subtitle, :sponsor, :title => @post.title
34
+ @sponsor_options.merge!({:company => "Github"})
35
+
36
+ page_subtitle "Keep Calm and %{text}", :text => "Call Batman"
37
+ page_subtitle "Keep Calm"
38
+
39
+ simple_helper :user_alert
40
+ @user_alert_options = {:username => @post.author}
41
+ ```
12
42
 
13
- Setting page title from I18n files.
43
+ If you didn't set the value manually, the gem will get it from your I18n backend.
14
44
 
15
45
  ```ruby
16
46
  en:
@@ -20,6 +50,15 @@ en:
20
50
  users:
21
51
  new: "Sign up"
22
52
  show: "%{name}'s Page"
53
+ subtitles:
54
+ simple_helper_default:
55
+ "Default page subtitle"
56
+ user_alerts:
57
+ users:
58
+ index: "This alert goes to %{username}"
59
+ sponsors:
60
+ simple_helper_default:
61
+ "The article %{title} is sponsored by %{company}."
23
62
  ```
24
63
 
25
64
  ### Interpolation
@@ -29,7 +68,7 @@ In many cases you want to abstract your translations so that variables can be in
29
68
  ```ruby
30
69
  page_title :name => @user.name
31
70
  or
32
- page_title_options.merge!({:name => "John Doe"})
71
+ @page_title_options.merge!({:name => "John Doe"})
33
72
  or
34
73
  simple_helper :page_title, :name => "John Doe"
35
74
  ```
@@ -80,33 +119,44 @@ This means that the I18n scope for the action "the_custom_action" will be the sa
80
119
  You can also specify a custom location at the "scope" key at the options hash, like rails does.
81
120
 
82
121
  ```ruby
83
- simple_helper :page_title, :scope => "my.awesome.chain", :name => "John Doe"
122
+ simple_helper :page_title, :scope => "my.awesome.chain", :name => "John"
84
123
  or
85
- page_title_options.merge!({:scope => "my.awesome.chain", :name => "John Doe"})
124
+ simple_helper :page_title
125
+ @page_title_options = {:scope => "my.awesome.chain", :name => "John"}
86
126
  ```
87
127
 
88
- ### Usage
89
-
90
- Other examples that could be called in your controllers:
128
+ Make sure you have this scope defined in a locale file:
91
129
 
92
130
  ```ruby
93
- simple_helper :page_subtitle, :special_message, :title => @post.title
94
- special_message_options.merge({:author => @post.author.name})
95
- page_subtitle "Keep Calm and %{text}", :text => "Call Batman"
96
- simple_helper :user_alert
131
+ en:
132
+ my:
133
+ awesome:
134
+ chain: "What's up %{name}?"
97
135
  ```
98
136
 
99
137
  ## Getting started
100
138
 
139
+ ### Instalation
140
+
141
+ ```ruby
142
+ gem install simple_helpers
143
+ ```
144
+
145
+ ### Setup
146
+
101
147
  Simple helpers works with Rails 3.0 onwards. You can add it to your Gemfile with:
102
148
 
103
- **gem 'simple_helpers'**
149
+ ```ruby
150
+ gem 'simple_helpers'
151
+ ```
104
152
 
105
153
  Run the bundle command to install it.
106
154
 
107
155
  After you install and add it to your Gemfile, you need to run the generator to create the initializer file. In this file you will configure the default behavior to your controllers.
108
156
 
109
- **rails generate simple_helpers**
157
+ ```ruby
158
+ rails generate simple_helpers
159
+ ```
110
160
 
111
161
  Take a look at the generated file:
112
162
 
data/Rakefile CHANGED
@@ -3,3 +3,5 @@ require "bundler/gem_tasks"
3
3
 
4
4
  require "rspec/core/rake_task"
5
5
  RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
@@ -20,8 +20,8 @@ module SimpleHelpers
20
20
  end
21
21
 
22
22
  define_method("#{name}_options") do
23
- options = instance_variable_get "@#{name}_options"
24
- options ||= {}
23
+ instance_variable_set("@#{name}_options", {}) unless instance_variable_get("@#{name}_options")
24
+ instance_variable_get("@#{name}_options")
25
25
  end
26
26
 
27
27
  define_method("#{name}_set") do |*args|
@@ -37,13 +37,13 @@ module SimpleHelpers
37
37
 
38
38
  result = value % options unless value.nil?
39
39
 
40
- # TODO: refactor
41
- new_options = options.delete_if{|k,v| k.to_sym == :scope}
40
+ # removing rails reserved word
41
+ helper_options = options.delete_if{|k,v| k.to_sym == :scope}
42
42
 
43
- result ||= t(scopes[:first], new_options)
43
+ result ||= t(scopes[:first], helper_options)
44
44
  if result.include? "translation missing" and scopes.has_key? :second
45
- new_options.merge! :default => result
46
- result = t(scopes[:second], new_options)
45
+ helper_options.merge! :default => result
46
+ result = t(scopes[:second], helper_options)
47
47
  end
48
48
 
49
49
  result
@@ -8,7 +8,6 @@ module SimpleHelpers
8
8
  end
9
9
 
10
10
  initializer "simple_helpers.initialize" do
11
-
12
11
  ::ActionController::Base.instance_eval do
13
12
  include SimpleHelpers::ActionController
14
13
 
@@ -23,9 +22,7 @@ module SimpleHelpers
23
22
 
24
23
  initialize_method.bind(self).call(*args)
25
24
  end
26
-
27
25
  end
28
-
29
26
  ::I18n.load_path += Dir[File.dirname(__FILE__) + "/../../locales/*.yml"]
30
27
  end
31
28
  end
@@ -2,7 +2,7 @@ module SimpleHelpers
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
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: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: -3047608726697320755
127
+ hash: 2960162122361549909
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: -3047608726697320755
136
+ hash: 2960162122361549909
137
137
  requirements: []
138
138
  rubyforge_project:
139
139
  rubygems_version: 1.8.23