heading_with_title 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e7e75808408afc7ae455d9b6b695e5be9a57f087
4
+ data.tar.gz: 086da7a96bb02e8e3e3ca1088046151a495cedf2
5
+ SHA512:
6
+ metadata.gz: b788c9bbf50703afb53e844b154174d53bbced8350ae7e685535978d830cbd73a31eb3e67e1c8c56f6cd6a2aaa557d05920b52732bc86af1bbc5cf1eaec54699
7
+ data.tar.gz: bcd32cf7dc0aeb8227ff9869858def12da7e9af672bf3e1fcaf3d43a264986ed755696c96f8c566aa377e1f88fdcad9d3cec7cb2240a32126074211a69ae2c50
data/README.md CHANGED
@@ -33,6 +33,15 @@ heading, or you call `page_title('Something')` to set page title without heading
33
33
  <span><%= heading %></span>
34
34
  <% end %>
35
35
 
36
+ # You can also call it without arguments. In this case
37
+ # it will use I18n Lazy Lookup (http://guides.rubyonrails.org/i18n.html#lazy-lookup)
38
+ # with key defined by `default_i18n_key` setting.
39
+ <%= heading_with_title %>
40
+
41
+ # If you need to use I18n Interpolation (http://guides.rubyonrails.org/i18n.html#interpolation)
42
+ # just pass hash as argument:
43
+ <%= heading_with_title username: 'John Doe' %>
44
+
36
45
  # Or you might want to set only page title
37
46
  <% page_title 'Users' %>
38
47
  ```
@@ -52,8 +61,23 @@ HeadingWithTitle.configure do |config|
52
61
 
53
62
  # Default heading size (h1 by default)
54
63
  config.default_heading_size = :h1
64
+
65
+ # Default I18n key when call heading_with_title
66
+ # helper without arguments
67
+ # Its the same as:
68
+ #
69
+ # heading_with_title t('.heading')
70
+ #
71
+ config.default_i18n_key = '.heading'
55
72
  end
56
73
  ```
74
+
75
+ ## Changelog
76
+
77
+ ### 0.0.2
78
+ * Ability to call `heading_with_title` without arguments. It uses I18n translation in this case.
79
+ * Support for I18n interpolation.
80
+
57
81
  ## License
58
82
 
59
83
  [The MIT License](https://github.com/tanraya/heading_with_title/blob/master/MIT-LICENSE)
@@ -13,7 +13,18 @@ module HeadingWithTitle
13
13
  end
14
14
  end
15
15
 
16
- def heading_with_title(heading, &block)
16
+ def heading_with_title(arg = nil, &block)
17
+ heading = case arg
18
+ when NilClass
19
+ t(HeadingWithTitle.default_i18n_key)
20
+ when Hash
21
+ t(HeadingWithTitle.default_i18n_key, arg)
22
+ when String
23
+ arg
24
+ else
25
+ raise ArgumentError, 'Incorrect arguments for heading_with_title!'
26
+ end
27
+
17
28
  page_title(heading)
18
29
  heading = raw(block.call(heading)) if block_given?
19
30
  content_tag(HeadingWithTitle.default_heading_size, heading)
@@ -1,3 +1,3 @@
1
1
  module HeadingWithTitle
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -24,6 +24,15 @@ require "action_view"
24
24
  # <span><%= heading %></span>
25
25
  # <% end %>
26
26
  #
27
+ # # You can also call it without arguments. In this case
28
+ # # it will use I18n Lazy Lookup (http://guides.rubyonrails.org/i18n.html#lazy-lookup)
29
+ # # with key defined by +default_i18n_key+ setting.
30
+ # <%= heading_with_title %>
31
+ #
32
+ # # If you need to use I18n Interpolation (http://guides.rubyonrails.org/i18n.html#interpolation)
33
+ # # just pass hash as argument:
34
+ # <%= heading_with_title username: 'John Doe' %>
35
+ #
27
36
  # Or you might want to set only page title
28
37
  # <% page_title 'Users' %>
29
38
  #
@@ -42,6 +51,14 @@ require "action_view"
42
51
  #
43
52
  # # Default heading size (h1 by default)
44
53
  # config.default_heading_size = :h1
54
+ #
55
+ # # Default I18n key when call heading_with_title
56
+ # # helper without arguments
57
+ # # Its the same as:
58
+ # #
59
+ # # heading_with_title t('.heading')
60
+ # #
61
+ # config.default_i18n_key = '.heading'
45
62
  # end
46
63
  #
47
64
  module HeadingWithTitle
@@ -58,6 +75,11 @@ module HeadingWithTitle
58
75
  mattr_accessor :default_heading_size
59
76
  @@default_heading_size = :h1
60
77
 
78
+ # Default I18n key when call heading_with_title
79
+ # helper without arguments
80
+ mattr_accessor :default_i18n_key
81
+ @@default_i18n_key = '.heading'
82
+
61
83
  def self.configure
62
84
  yield self
63
85
  end
@@ -1,11 +1,21 @@
1
1
  # encoding: utf-8
2
2
  require "heading_with_title"
3
3
 
4
+ module HeadingWithTitle
5
+ module Helpers #:nodoc:
6
+ def t(*args)
7
+ I18n.t(*args)
8
+ end
9
+ end
10
+ end
11
+
4
12
  describe HeadingWithTitle::Helpers do
5
13
  include ActionView::Helpers
6
14
  include HeadingWithTitle::Helpers
7
15
 
8
- before { Rails.stub_chain(:application, :name).and_return('AwesomeApp') }
16
+ before do
17
+ Rails.stub_chain(:application, :name).and_return('AwesomeApp')
18
+ end
9
19
 
10
20
  describe '.page_title' do
11
21
  it 'sets a page title' do
@@ -48,5 +58,19 @@ describe HeadingWithTitle::Helpers do
48
58
  HeadingWithTitle.default_heading_size = :h2
49
59
  heading_with_title('Users').should == '<h2>Users</h2>'
50
60
  end
61
+
62
+ it 'uses I18n when called without args' do
63
+ HeadingWithTitle.default_heading_size = :h1
64
+ heading_with_title.should == '<h1>translation missing: en.heading</h1>'
65
+ end
66
+
67
+ it 'allows hash as arguments (I18n interpolation)' do
68
+ I18n.backend.store_translations :en, heading: 'Hello %{name}!'
69
+ heading_with_title(name: 'John Doe').should == '<h1>Hello John Doe!</h1>'
70
+ end
71
+
72
+ it 'raises ArgumentError on incorrect arguments' do
73
+ expect { heading_with_title(OpenStruct.new(name: 'Weird')) }.to raise_error(ArgumentError, 'Incorrect arguments for heading_with_title!')
74
+ end
51
75
  end
52
76
  end
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heading_with_title
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andrew Kozloff
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-27 00:00:00.000000000 Z
11
+ date: 2013-12-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,33 +41,29 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Setting the page heading at the same time with a page title
@@ -96,27 +87,26 @@ files:
96
87
  homepage: https://github.com/rocsci/heading_with_title
97
88
  licenses:
98
89
  - MIT
90
+ metadata: {}
99
91
  post_install_message:
100
92
  rdoc_options: []
101
93
  require_paths:
102
94
  - lib
103
95
  required_ruby_version: !ruby/object:Gem::Requirement
104
- none: false
105
96
  requirements:
106
- - - ! '>='
97
+ - - '>='
107
98
  - !ruby/object:Gem::Version
108
99
  version: '0'
109
100
  required_rubygems_version: !ruby/object:Gem::Requirement
110
- none: false
111
101
  requirements:
112
- - - ! '>='
102
+ - - '>='
113
103
  - !ruby/object:Gem::Version
114
104
  version: '0'
115
105
  requirements: []
116
106
  rubyforge_project:
117
- rubygems_version: 1.8.24
107
+ rubygems_version: 2.1.11
118
108
  signing_key:
119
- specification_version: 3
109
+ specification_version: 4
120
110
  summary: A set of helpers for Rails
121
111
  test_files:
122
112
  - spec/heading_with_title/helpers_spec.rb