metanol 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -6,7 +6,7 @@ This is a meta tags plugin which helps to manage meta tags in your Rails applica
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'metanol'
9
+ gem 'metanol', '~> 0.0.4'
10
10
 
11
11
  And then execute:
12
12
 
@@ -18,6 +18,8 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### Methods of a Controller
22
+
21
23
  There are two ways to set meta tags. The first one is a setting values for meta tags in a controller:
22
24
 
23
25
  ```ruby
@@ -66,12 +68,21 @@ There are some filters which you can set for methods above:
66
68
  * `whitespaces` - to get rid of whitespaces in a value (i.e. `meta({title: "Page title", description: 'Page description'}, :html, :whitespaces)`)
67
69
  * `clean` - apply `html`, `overspaces` and `whitespaces` filters for a value
68
70
 
71
+ There are some methods for getting a meta's value:
72
+ * `get_meta(name)` - returns a value of a specified HTML meta tag
73
+ * `get_og_meta(name)` - returns a value of a specified OpenGraph meta tags
74
+ * `get_wm_meta(name)` - returns a value of a specified Webmaster meta tags
75
+
76
+ ### Helpers
77
+
69
78
  Here is the helper's methods for rendering meta tags:
70
79
  * `metanol_tags` - renders all meta tags (Webmaster, OpenGraph and other)
71
80
  * `metanol_og_tags` - renders only OpenGraph's meta tags
72
81
  * `metanol_wm_tags` - renders Webmaster verification tags
73
82
  * `metanol_main_tags` - renders other meta tags, such as keywords, description, etc.
74
83
 
84
+ Also the plugin provides some helper's methods for getting a meta's value: `get_meta(name)`, `get_og_meta(name)`, `get_wm_meta(name)`.
85
+
75
86
  ## Contributing
76
87
 
77
88
  1. Fork it
@@ -27,6 +27,18 @@ module Metanol
27
27
  add_meta_tag(:wm, *args)
28
28
  end
29
29
 
30
+ def get_meta(name)
31
+ get_meta_by_type(:main, name)
32
+ end
33
+
34
+ def get_og_meta(name)
35
+ get_meta_by_type(:og, name)
36
+ end
37
+
38
+ def get_wm_meta(name)
39
+ get_meta_by_type(:wm, name)
40
+ end
41
+
30
42
  private
31
43
 
32
44
  def add_meta_tag(type, *args)
@@ -54,6 +66,12 @@ module Metanol
54
66
  end
55
67
  end
56
68
 
69
+ def get_meta_by_type(type, name)
70
+ data = meta_data(name)[type]
71
+ key = data[:key]
72
+ metanol_options.key?(key) ? metanol_options[key].value : nil
73
+ end
74
+
57
75
  def meta_data(name)
58
76
  {
59
77
  main: { key: name, type: Meta::Main },
@@ -79,6 +97,18 @@ module Metanol
79
97
  self.class.metanol_options
80
98
  end
81
99
 
100
+ def get_meta(name)
101
+ self.class.get_meta name
102
+ end
103
+
104
+ def get_og_meta(name)
105
+ self.class.get_og_meta name
106
+ end
107
+
108
+ def get_wm_meta(name)
109
+ self.class.get_wm_meta name
110
+ end
111
+
82
112
  end
83
113
 
84
114
  end
@@ -31,6 +31,18 @@ module Metanol
31
31
  request.original_url
32
32
  end
33
33
 
34
+ def get_meta(name)
35
+ self.controller.get_meta(name)
36
+ end
37
+
38
+ def get_og_meta(name)
39
+ self.controller.get_og_meta(name)
40
+ end
41
+
42
+ def get_wm_meta(name)
43
+ self.controller.get_wm_meta(name)
44
+ end
45
+
34
46
  private
35
47
 
36
48
  def metanol_render_tags(type)
@@ -1,3 +1,3 @@
1
1
  module Metanol
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -153,4 +153,35 @@ describe TestsController do
153
153
  it { response.should have_selector('meta[content=" Description for a users list"]', name: 'description') }
154
154
  end
155
155
 
156
+ context "returns meta values in a controller and in a view" do
157
+ controller do
158
+ def index
159
+ meta :title, 'Users List'
160
+ wm_meta :alexa, 'alexa code'
161
+ og_meta title: 'OpenGraph Title'
162
+
163
+ @meta = get_meta :title
164
+ @wm_meta = get_wm_meta :alexa
165
+ @og_meta = get_og_meta :title
166
+ @og_no_meta = get_og_meta :bad_meta_name
167
+
168
+ render :inline => <<-ERB
169
+ <span>Main meta is <%= get_meta :title %></span>
170
+ <span>OpenGraph meta is <%= get_og_meta :title %></span>
171
+ <span>Webmaster meta is <%= get_wm_meta :alexa %></span>
172
+ ERB
173
+ end
174
+ end
175
+
176
+ before { get :index }
177
+
178
+ it { response.should have_selector('span', content: 'Main meta is Users List') }
179
+ it { response.should have_selector('span', content: 'OpenGraph meta is OpenGraph Title') }
180
+ it { response.should have_selector('span', content: 'Webmaster meta is alexa code') }
181
+ it { assigns(:meta).should == 'Users List' }
182
+ it { assigns(:wm_meta).should == 'alexa code' }
183
+ it { assigns(:og_meta).should == 'OpenGraph Title' }
184
+ it { assigns(:og_no_meta).should == nil }
185
+ end
186
+
156
187
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails