layout_values 0.0.1

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: f0d3b3f120cf306104bc1d6d8cb29e3994512c72
4
+ data.tar.gz: d08470f4208c8ff3c75982b51bcca06465d00f84
5
+ SHA512:
6
+ metadata.gz: 4e016520d485ae551c684836f6501d144d7a3b5ebf93145e57e8962836d6b52b1a075c816b52a4257f7463feb68c852791290c0f16d0cf77d54b8f22b8ccd605
7
+ data.tar.gz: 382ef14fa283cd2782c3dd8f7a672297cbb9a4fdacd669c0debd91e24d6d284ad4aa1c2a1ef6e2a9cceea6d7b16e021a7911048116cb1f2267a9e07ddd02a5e2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # LayoutValues
2
+
3
+ Rails plugin to add helpers to indicate page titles and meta description.
4
+
5
+ Usage
6
+ -----
7
+
8
+ In your layout:
9
+
10
+ ```erb
11
+ <title><%= title %></title>
12
+ <meta name="description" content="<%= meta_description %>" />
13
+ ```
14
+
15
+ In your views:
16
+
17
+ ```erb
18
+ <% title "Best Page Ever" %>
19
+ <% meta_description "The best page ever on the internets" %>
20
+ ```
21
+
22
+ Or even:
23
+
24
+ ```erb
25
+ <h1><%= title "Best Page Ever" %></h1>
26
+ ```
27
+
28
+ You can use translation files to customize the title:
29
+
30
+ ```yml
31
+ en:
32
+ layout:
33
+ title:
34
+ format: "%{title} — My Site"
35
+ default: "My Site"
36
+ meta_description:
37
+ format: "%{meta_description}, via My Site"
38
+ default: "My description"
39
+ meta_keywords:
40
+ format: "%{meta_keywords}"
41
+ default: "mysite"
42
+ ```
43
+
44
+ You can also set titles in your translation files directly
45
+ by controller and action:
46
+
47
+ ```yml
48
+ fr:
49
+ users:
50
+ show:
51
+ title: "Mon compte"
52
+ meta_description: "Éditer mon compte"
53
+ ```
54
+
55
+
56
+ Requirements
57
+ ------------
58
+
59
+ Rails 4, Ruby 2.
60
+
61
+ Install
62
+ -------
63
+
64
+ Add this line to your Gemfile:
65
+
66
+ ```rb
67
+ gem "layout_values", github: "sunny/layout_values"
68
+ ```
69
+
70
+ Install it:
71
+
72
+ ```sh
73
+ $ bundle
74
+ ```
75
+
76
+ Then in `app/helpers/application_helper.rb`, add:
77
+
78
+ ```rb
79
+ module ApplicationHelper
80
+ include LayoutValuesHelper
81
+ end
82
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'LayoutValues'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,35 @@
1
+ module LayoutValuesHelper
2
+
3
+ %i(title meta_description meta_keywords).each do |method|
4
+ define_method method do |value = nil|
5
+ if value.present?
6
+ content_for method, value.html_safe.to_s
7
+ value
8
+ else
9
+ layout_value(method)
10
+ end
11
+ end
12
+ end
13
+
14
+
15
+ private
16
+ def layout_value(key)
17
+ # Read
18
+ if content_for?(key)
19
+ value = content_for(key)
20
+ else
21
+ value = t("#{controller.controller_name}.#{controller.action_name}.#{key}", default: "")
22
+ end
23
+
24
+ # Decorate
25
+ if value.present?
26
+ value = t("layout.#{key}.format", key.to_sym => value, default: value)
27
+ else
28
+ value = t("layout.#{key}.default", default: value)
29
+ end
30
+
31
+ # Translation helpers tend to add HTML
32
+ strip_tags value
33
+ end
34
+
35
+ end
@@ -0,0 +1,4 @@
1
+ require "layout_values/engine"
2
+
3
+ module LayoutValues
4
+ end
@@ -0,0 +1,4 @@
1
+ module LayoutValues
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module LayoutValues
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: layout_values
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sunny Ripert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - sunny@sunfox.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - app/helpers/layout_values_helper.rb
49
+ - lib/layout_values/engine.rb
50
+ - lib/layout_values/version.rb
51
+ - lib/layout_values.rb
52
+ - MIT-LICENSE
53
+ - Rakefile
54
+ - README.md
55
+ homepage: http://github.com/sunny
56
+ licenses: []
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.1.11
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Add helpers to indicate page titles and meta description.
78
+ test_files: []