dyn_meta 0.0.5 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3-p194@dyn_meta --create
data/Gemfile CHANGED
@@ -1,16 +1,6 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'https://rubygems.org'
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
3
+ # Specify your gem's dependencies in dyn_meta.gemspec
4
+ gemspec
8
5
 
9
- gem "rails"
10
-
11
- group :development do
12
- gem "rspec", "~> 2.1.0"
13
- gem "cucumber", ">= 0"
14
- gem "bundler", "~> 1.0.0"
15
- gem "jeweler", "~> 1.5.1"
16
- end
6
+ gem 'rspec'
@@ -1,100 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dyn_meta (0.1.1)
5
+ activesupport
6
+
1
7
  GEM
2
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
3
9
  specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.3)
6
- actionpack (= 3.0.3)
7
- mail (~> 2.2.9)
8
- actionpack (3.0.3)
9
- activemodel (= 3.0.3)
10
- activesupport (= 3.0.3)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.6)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.3)
19
- activesupport (= 3.0.3)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4)
22
- activerecord (3.0.3)
23
- activemodel (= 3.0.3)
24
- activesupport (= 3.0.3)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.3)
28
- activemodel (= 3.0.3)
29
- activesupport (= 3.0.3)
30
- activesupport (3.0.3)
31
- arel (2.0.6)
32
- builder (2.1.2)
33
- cucumber (0.9.4)
34
- builder (~> 2.1.2)
35
- diff-lcs (~> 1.1.2)
36
- gherkin (~> 2.2.9)
37
- json (~> 1.4.6)
38
- term-ansicolor (~> 1.0.5)
39
- diff-lcs (1.1.2)
40
- erubis (2.6.6)
41
- abstract (>= 1.0.0)
42
- gherkin (2.2.9)
43
- json (~> 1.4.6)
44
- term-ansicolor (~> 1.0.5)
45
- git (1.2.5)
46
- i18n (0.5.0)
47
- jeweler (1.5.1)
48
- bundler (~> 1.0.0)
49
- git (>= 1.2.5)
50
- rake
51
- json (1.4.6)
52
- mail (2.2.12)
53
- activesupport (>= 2.3.6)
54
- i18n (>= 0.4.0)
55
- mime-types (~> 1.16)
56
- treetop (~> 1.4.8)
57
- mime-types (1.16)
58
- polyglot (0.3.1)
59
- rack (1.2.1)
60
- rack-mount (0.6.13)
61
- rack (>= 1.0.0)
62
- rack-test (0.5.6)
63
- rack (>= 1.0)
64
- rails (3.0.3)
65
- actionmailer (= 3.0.3)
66
- actionpack (= 3.0.3)
67
- activerecord (= 3.0.3)
68
- activeresource (= 3.0.3)
69
- activesupport (= 3.0.3)
70
- bundler (~> 1.0)
71
- railties (= 3.0.3)
72
- railties (3.0.3)
73
- actionpack (= 3.0.3)
74
- activesupport (= 3.0.3)
75
- rake (>= 0.8.7)
76
- thor (~> 0.14.4)
77
- rake (0.8.7)
78
- rspec (2.1.0)
79
- rspec-core (~> 2.1.0)
80
- rspec-expectations (~> 2.1.0)
81
- rspec-mocks (~> 2.1.0)
82
- rspec-core (2.1.0)
83
- rspec-expectations (2.1.0)
84
- diff-lcs (~> 1.1.2)
85
- rspec-mocks (2.1.0)
86
- term-ansicolor (1.0.5)
87
- thor (0.14.6)
88
- treetop (1.4.9)
89
- polyglot (>= 0.3.1)
90
- tzinfo (0.3.23)
10
+ activesupport (3.2.11)
11
+ i18n (~> 0.6)
12
+ multi_json (~> 1.0)
13
+ diff-lcs (1.1.3)
14
+ i18n (0.6.1)
15
+ multi_json (1.5.0)
16
+ rspec (2.12.0)
17
+ rspec-core (~> 2.12.0)
18
+ rspec-expectations (~> 2.12.0)
19
+ rspec-mocks (~> 2.12.0)
20
+ rspec-core (2.12.2)
21
+ rspec-expectations (2.12.1)
22
+ diff-lcs (~> 1.1.3)
23
+ rspec-mocks (2.12.1)
91
24
 
92
25
  PLATFORMS
93
26
  ruby
94
27
 
95
28
  DEPENDENCIES
96
- bundler (~> 1.0.0)
97
- cucumber
98
- jeweler (~> 1.5.1)
99
- rails
100
- rspec (~> 2.1.0)
29
+ dyn_meta!
30
+ rspec
@@ -1,4 +1,6 @@
1
- Copyright (c) 2010 Mike Nelson
1
+ Copyright (c) 2013 Mike Nelson
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
21
  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.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,89 @@
1
+ # DynMeta
2
+
3
+ Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.
4
+
5
+ ## Installation
6
+
7
+ Add dyn_meta to your Gemfile
8
+
9
+ gem 'dyn_meta'
10
+
11
+ Install the gem
12
+
13
+ bundle install
14
+
15
+ ## Usage
16
+
17
+ Set up your translations as follows:
18
+
19
+ ```yml
20
+ en:
21
+ meta:
22
+ <meta key pluralized>:
23
+ <controller>:
24
+ <action>:
25
+ <id>: "Some meta value"
26
+ ```
27
+
28
+ For example:
29
+
30
+ ```yml
31
+ en:
32
+ meta:
33
+ titles:
34
+ users:
35
+ new: "Create Your Account"
36
+ edit: "Update Your Account"
37
+ ```
38
+
39
+ You usually won't go down to the `id` level but occasionally it's useful:
40
+
41
+ ```yml
42
+ en:
43
+ meta:
44
+ titles:
45
+ pages:
46
+ show:
47
+ tos: "Terms of Service"
48
+ pp: "Privacy Policy"
49
+ about: "About My Site"
50
+ ```
51
+
52
+ You can define catch-alls via the `default` key:
53
+
54
+ ```yml
55
+ en:
56
+ meta:
57
+ titles:
58
+ default: "My Super Site"
59
+ users:
60
+ default: "Manage Your Account"
61
+ new: "Create Your Account"
62
+ edit: "Update Your Account"
63
+ ```
64
+
65
+ DynMeta provides one method *meta*. It's both a setter and a getter. Just use the *meta* method in your template:
66
+
67
+ ```erb
68
+ <title><%= meta(:title) %></title>
69
+ <meta name="description" content="<%= meta(:description) %>" />
70
+ ```
71
+
72
+ If you'd like to override meta content you can just pass a value to the *meta* method:
73
+
74
+ ```ruby
75
+ def show
76
+ @user = User.find(params[:id])
77
+ meta(:title, "#{@user.display_name} :: Profile")
78
+ end
79
+ ```
80
+
81
+ You can also provide interpolations via the meta method rather than overriding entire locales:
82
+
83
+ ```ruby
84
+ def show
85
+ @user = User.find(params[:id])
86
+ meta(:title, :name => @user.display_name})
87
+ end
88
+ ```
89
+
data/Rakefile CHANGED
@@ -1,55 +1 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "dyn_meta"
16
- gem.homepage = "http://github.com/mnelson/dyn_meta"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Automate the lookup of page meta information based on the current request context}
19
- gem.description = %Q{Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.}
20
- gem.email = "mike@mikeonrails.com"
21
- gem.authors = ["Mike Nelson"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- gem.add_runtime_dependency 'rails', '>= 2.0'
25
- gem.add_runtime_dependency 'i18n', '> 0.0'
26
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
27
- # gem.add_development_dependency 'rspec', '> 1.2.3'
28
- end
29
- Jeweler::RubygemsDotOrgTasks.new
30
-
31
- require 'rspec/core'
32
- require 'rspec/core/rake_task'
33
- RSpec::Core::RakeTask.new(:spec) do |spec|
34
- spec.pattern = FileList['spec/**/*_spec.rb']
35
- end
36
-
37
- RSpec::Core::RakeTask.new(:rcov) do |spec|
38
- spec.pattern = 'spec/**/*_spec.rb'
39
- spec.rcov = true
40
- end
41
-
42
- require 'cucumber/rake/task'
43
- Cucumber::Rake::Task.new(:features)
44
-
45
- task :default => :spec
46
-
47
- require 'rake/rdoctask'
48
- Rake::RDocTask.new do |rdoc|
49
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
-
51
- rdoc.rdoc_dir = 'rdoc'
52
- rdoc.title = "dyn_meta #{version}"
53
- rdoc.rdoc_files.include('README*')
54
- rdoc.rdoc_files.include('lib/**/*.rb')
55
- end
1
+ require "bundler/gem_tasks"
@@ -1,80 +1,21 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dyn_meta/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{dyn_meta}
8
- s.version = "0.0.5"
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "dyn_meta"
8
+ gem.version = DynMeta::VERSION
9
+ gem.authors = ["Mike Nelson"]
10
+ gem.email = ["mike@mikeonrails.com"]
11
+ gem.description = %q{Simple translation lookup based on the current request context.}
12
+ gem.summary = %q{Simple request-based translation lookup.}
13
+ gem.homepage = ""
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Mike Nelson"]
12
- s.date = %q{2011-10-25}
13
- s.description = %q{Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.}
14
- s.email = %q{mike@mikeonrails.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".rspec",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "dyn_meta-0.0.3.gem",
29
- "dyn_meta.gemspec",
30
- "features/dyn_meta.feature",
31
- "features/step_definitions/dyn_meta_steps.rb",
32
- "features/support/env.rb",
33
- "lib/dyn_meta.rb",
34
- "lib/dyn_meta/action_controller.rb",
35
- "spec/dyn_meta_spec.rb",
36
- "spec/en.yml",
37
- "spec/spec_helper.rb"
38
- ]
39
- s.homepage = %q{http://github.com/mnelson/dyn_meta}
40
- s.licenses = ["MIT"]
41
- s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.6}
43
- s.summary = %q{Automate the lookup of page meta information based on the current request context}
44
- s.test_files = [
45
- "spec/dyn_meta_spec.rb",
46
- "spec/spec_helper.rb"
47
- ]
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
48
19
 
49
- if s.respond_to? :specification_version then
50
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
- s.specification_version = 3
52
-
53
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
- s.add_runtime_dependency(%q<rails>, [">= 0"])
55
- s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
56
- s.add_development_dependency(%q<cucumber>, [">= 0"])
57
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
58
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
59
- s.add_runtime_dependency(%q<rails>, [">= 2.0"])
60
- s.add_runtime_dependency(%q<i18n>, ["> 0.0"])
61
- else
62
- s.add_dependency(%q<rails>, [">= 0"])
63
- s.add_dependency(%q<rspec>, ["~> 2.1.0"])
64
- s.add_dependency(%q<cucumber>, [">= 0"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
67
- s.add_dependency(%q<rails>, [">= 2.0"])
68
- s.add_dependency(%q<i18n>, ["> 0.0"])
69
- end
70
- else
71
- s.add_dependency(%q<rails>, [">= 0"])
72
- s.add_dependency(%q<rspec>, ["~> 2.1.0"])
73
- s.add_dependency(%q<cucumber>, [">= 0"])
74
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
75
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
76
- s.add_dependency(%q<rails>, [">= 2.0"])
77
- s.add_dependency(%q<i18n>, ["> 0.0"])
78
- end
20
+ gem.add_dependency 'activesupport'
79
21
  end
80
-
Binary file
@@ -1 +1,78 @@
1
- require 'dyn_meta/action_controller'
1
+ require 'dyn_meta/version'
2
+ require 'active_support/core_ext/string/inflections'
3
+ require 'active_support/core_ext/hash/except'
4
+ require 'active_support/core_ext/object/blank'
5
+
6
+ module DynMeta
7
+
8
+ module Helper
9
+
10
+
11
+ # allow setting, getting, and configuration of meta content.
12
+ # utilizes i18n and the current request to build meta content
13
+ #
14
+ # Usage:
15
+ # Request 1:
16
+ # meta(:page_title, "Some String") => "Some String"
17
+ # meta(:page_title) => "Some String"
18
+ # Request 2:
19
+ # assuming t('meta.page_titles.[controller].[action].default') == "Some Page Title"
20
+ # meta(:page_title) => "Some Page Title"
21
+ # Request 3:
22
+ # assuming t('meta.page_titles.[controller].[action].default') == "%{geo_name} Title"
23
+ # meta(:page_title, :geo_name => "Atlantis")
24
+ # meta(:page_title) => "Atlantis Title"
25
+ # Request 4:
26
+ # assuming t('meta.page_titles.[controller].custom_action.default') == "Special Title"
27
+ # meta(:page_title, :alt => {:action => 'custom_action'}) => "Special Title"
28
+ # meta(:page_title) => "Special Title"
29
+ def meta(name, interpolations = nil)
30
+
31
+ instance_name = "@dyn_meta_#{name}"
32
+
33
+ return instance_variable_get(instance_name) if interpolations.nil? && instance_variable_get(instance_name)
34
+ return instance_variable_set(instance_name, interpolations) if interpolations.is_a?(String)
35
+
36
+ interpolations ||= {}
37
+ alt_params = interpolations[:alt] || {}
38
+ param_hash = params.merge(alt_params)
39
+
40
+ interpolations.except!(:alt)
41
+
42
+ keys = ["#{meta_key}.#{name.to_s.pluralize}", "#{meta_key}.#{name.to_s.pluralize}.default"]
43
+
44
+ [:controller, :action, :id].each do |param|
45
+ key = param_hash[param]
46
+ break if key.blank?
47
+ prev = keys.first
48
+ keys.unshift("#{prev}.#{key}.default")
49
+ keys.unshift("#{prev}.#{key}")
50
+ end
51
+
52
+ val = meta_lookup(keys, interpolations)
53
+
54
+ instance_variable_set(instance_name, val)
55
+ end
56
+
57
+ protected
58
+
59
+ def meta_lookup(keys, interpolations)
60
+ keys.each do |key|
61
+ val = begin
62
+ I18n.t(key, interpolations.merge(raise: true))
63
+ rescue I18n::MissingTranslationData
64
+ nil
65
+ end
66
+
67
+ next if val.is_a?(Hash)
68
+ return val if val
69
+ end
70
+
71
+ nil
72
+ end
73
+
74
+ def meta_key
75
+ 'meta'
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module DynMeta
2
+ VERSION = '0.1.1'
3
+ end
@@ -1,47 +1,75 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
-
4
- describe "DynMeta" do
5
-
6
- it "should have translations loaded" do
7
- I18n.translate(:foo).should eql('bar')
8
- end
9
-
10
- it "should have dyn_meta methods included" do
11
- a = controller
12
- a.respond_to?(:meta).should be_true
13
- end
14
-
15
- it "should define instance variables when they don't exist" do
16
- a = controller
17
- a.instance_variable_get('@meta_title').should be_nil
18
- a.meta(:title, 'value')
19
- a.instance_variable_get('@meta_title').should eql('value')
20
- end
21
-
22
- it "should return nil when trans hash doesn't exist" do
23
- a = controller
24
- a.meta(:description).should be_nil
25
- end
26
-
27
- it "should look at controller action and id for translations" do
28
- a = controller(:controller => 'users', :action => 'edit')
29
- a.meta(:title).should eql("Update your account")
30
- a.meta(:title).should eql("Update your account")
31
- end
32
-
33
- it "should fall back to default values" do
34
- controller.meta(:title).should eql("Users, this is for you")
35
- controller({:controller => 'organizations'}).meta(:title).should eql("My Great Startup Idea")
36
- end
37
-
38
-
39
- private
40
-
41
- def controller(params = {:controller => 'users'})
42
- a = ActionController::Base.new
43
- a.params = params
44
- a
1
+ require 'spec_helper'
2
+
3
+ describe DynMeta::Helper do
4
+
5
+ class Controller
6
+ include DynMeta::Helper
7
+
8
+ attr_reader :params
9
+ def initialize(params = {})
10
+ @params = params
11
+ end
12
+ end
13
+
14
+ let(:params){ {:controller => 'testing', :action => 'show'} }
15
+ let(:c){ Controller.new(params) }
16
+
17
+ before do
18
+ I18n.locale = :en
19
+ end
20
+
21
+ it 'should integrate for testing properly' do
22
+ c.params.should eql(params)
23
+ c.should respond_to(:meta)
24
+ end
25
+
26
+ it 'should allow direct setting of the value' do
27
+ c.meta(:title, 'Title of the page')
28
+ c.meta(:title).should eql('Title of the page')
29
+ end
30
+
31
+ it 'should read values from I18n' do
32
+ c.meta(:keywords).should eql('testing,show,dyn_meta')
33
+ end
34
+
35
+ it 'should interpolate values and memoize results' do
36
+ params[:action] = 'index'
37
+ c.meta(:keywords, :type => 'user').should eql('testing,index,dyn_meta,user')
38
+ c.meta(:keywords).should eql('testing,index,dyn_meta,user')
39
+ end
40
+
41
+ it 'should allow substitutions to be provided' do
42
+ c.meta(:keywords, :type => 'user', :alt => {:action => 'index'}).should eql('testing,index,dyn_meta,user')
43
+ end
44
+
45
+ it 'should work down to the id level' do
46
+ params.merge!(:controller => 'pages', :action => 'show', :id => 'tos')
47
+ c.meta(:keywords).should eql('pages,show,tos,dyn_meta')
48
+ end
49
+
50
+ it 'should use the default when provided' do
51
+ params.merge!(:controller => 'pages', :action => 'show', :id => nil)
52
+ c.meta(:keywords).should eql('pages,show,default,dyn_meta')
53
+ end
54
+
55
+ it 'should use the top level default when no matches are found' do
56
+ params.merge!(:controller => 'users', :action => 'show', :id => 'doug')
57
+ c.meta(:keywords).should eql('dyn_meta')
58
+ end
59
+
60
+ context do
61
+ before do
62
+ I18n.locale = :"en-US"
63
+ end
64
+
65
+ it 'should use the correct backups when a locale key is missing' do
66
+ params.merge!(:controller => 'testing', action: 'show')
67
+ c.meta(:page_title).should eql('Testing controller show action page title')
45
68
  end
46
-
69
+
70
+ it 'should use the locale key if present' do
71
+ params.merge!(:controller => 'anything', action: 'other')
72
+ c.meta(:page_title).should eql('Default page title in the US')
73
+ end
74
+ end
47
75
  end
@@ -1,16 +1,64 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'rubygems'
5
- require 'rails/all'
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
6
8
  require 'dyn_meta'
9
+ require 'i18n'
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
7
15
 
8
- # Requires supporting files with custom matchers and macros, etc,
9
- # in ./support/ and its subdirectories.
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
11
21
 
12
- I18n.backend.send(:load_file, File.join(File.dirname(__FILE__), 'en.yml'))
22
+ config.before :suite do
13
23
 
14
- RSpec.configure do |config|
15
-
24
+ require "i18n/backend/fallbacks"
25
+ I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
26
+ I18n.fallbacks.map(:"en-US" => :en)
27
+
28
+ I18n.backend.store_translations(:en, {
29
+ 'meta' => {
30
+ 'page_titles' => {
31
+ 'default' => 'Default page title',
32
+ 'testing' => {
33
+ 'default' => 'Default testing controller page title',
34
+ 'show' => 'Testing controller show action page title'
35
+ }
36
+ },
37
+ 'keywords' => {
38
+ 'default' => 'dyn_meta',
39
+ 'testing' => {
40
+ 'default' => 'testing,dyn_meta',
41
+ 'show' => 'testing,show,dyn_meta',
42
+ 'index' => 'testing,index,dyn_meta,%{type}'
43
+ },
44
+ 'pages' => {
45
+ 'default' => 'pages,default,dyn_meta',
46
+ 'show' => {
47
+ 'default' => 'pages,show,default,dyn_meta',
48
+ 'tos' => 'pages,show,tos,dyn_meta'
49
+ }
50
+ }
51
+ }
52
+ }
53
+ })
54
+
55
+ I18n.backend.store_translations(:"en-US", {
56
+ 'meta' => {
57
+ 'page_titles' => {
58
+ 'default' => 'Default page title in the US'
59
+ }
60
+ }
61
+ })
62
+
63
+ end
16
64
  end
metadata CHANGED
@@ -1,172 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dyn_meta
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 5
9
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Mike Nelson
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-10-25 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- segments:
26
- - 0
27
- version: "0"
28
- requirement: *id001
29
- name: rails
30
- prerelease: false
31
- type: :runtime
32
- - !ruby/object:Gem::Dependency
33
- version_requirements: &id002 !ruby/object:Gem::Requirement
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- segments:
38
- - 2
39
- - 1
40
- - 0
41
- version: 2.1.0
42
- requirement: *id002
43
- name: rspec
44
- prerelease: false
45
- type: :development
46
- - !ruby/object:Gem::Dependency
47
- version_requirements: &id003 !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- segments:
52
- - 0
53
- version: "0"
54
- requirement: *id003
55
- name: cucumber
56
- prerelease: false
57
- type: :development
58
- - !ruby/object:Gem::Dependency
59
- version_requirements: &id004 !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ~>
62
- - !ruby/object:Gem::Version
63
- segments:
64
- - 1
65
- - 0
66
- - 0
67
- version: 1.0.0
68
- requirement: *id004
69
- name: bundler
70
- prerelease: false
71
- type: :development
72
- - !ruby/object:Gem::Dependency
73
- version_requirements: &id005 !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- segments:
78
- - 1
79
- - 5
80
- - 1
81
- version: 1.5.1
82
- requirement: *id005
83
- name: jeweler
84
- prerelease: false
85
- type: :development
86
- - !ruby/object:Gem::Dependency
87
- version_requirements: &id006 !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- segments:
92
- - 2
93
- - 0
94
- version: "2.0"
95
- requirement: *id006
96
- name: rails
97
- prerelease: false
12
+ date: 2014-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
98
22
  type: :runtime
99
- - !ruby/object:Gem::Dependency
100
- version_requirements: &id007 !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ">"
103
- - !ruby/object:Gem::Version
104
- segments:
105
- - 0
106
- - 0
107
- version: "0.0"
108
- requirement: *id007
109
- name: i18n
110
23
  prerelease: false
111
- type: :runtime
112
- description: Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.
113
- email: mike@mikeonrails.com
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Simple translation lookup based on the current request context.
31
+ email:
32
+ - mike@mikeonrails.com
114
33
  executables: []
115
-
116
34
  extensions: []
117
-
118
- extra_rdoc_files:
119
- - LICENSE.txt
120
- - README.rdoc
121
- files:
122
- - .document
123
- - .rspec
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rvmrc
124
39
  - Gemfile
125
40
  - Gemfile.lock
126
41
  - LICENSE.txt
127
- - README.rdoc
42
+ - README.md
128
43
  - Rakefile
129
- - VERSION
130
- - dyn_meta-0.0.3.gem
131
44
  - dyn_meta.gemspec
132
- - features/dyn_meta.feature
133
- - features/step_definitions/dyn_meta_steps.rb
134
- - features/support/env.rb
45
+ - lib/.DS_Store
135
46
  - lib/dyn_meta.rb
136
- - lib/dyn_meta/action_controller.rb
47
+ - lib/dyn_meta/version.rb
137
48
  - spec/dyn_meta_spec.rb
138
- - spec/en.yml
139
49
  - spec/spec_helper.rb
140
- has_rdoc: true
141
- homepage: http://github.com/mnelson/dyn_meta
142
- licenses:
143
- - MIT
50
+ homepage: ''
51
+ licenses: []
144
52
  post_install_message:
145
53
  rdoc_options: []
146
-
147
- require_paths:
54
+ require_paths:
148
55
  - lib
149
- required_ruby_version: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- segments:
154
- - 0
155
- version: "0"
156
- required_rubygems_version: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- segments:
161
- - 0
162
- version: "0"
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
163
68
  requirements: []
164
-
165
69
  rubyforge_project:
166
- rubygems_version: 1.3.6
70
+ rubygems_version: 1.8.25
167
71
  signing_key:
168
72
  specification_version: 3
169
- summary: Automate the lookup of page meta information based on the current request context
170
- test_files:
73
+ summary: Simple request-based translation lookup.
74
+ test_files:
171
75
  - spec/dyn_meta_spec.rb
172
76
  - spec/spec_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,73 +0,0 @@
1
- = DynMeta
2
-
3
- Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.
4
-
5
- == Please Note
6
-
7
- The usage of dyn_meta has changed from *page_* methods to a simple *meta* method.
8
-
9
- == Installation
10
-
11
- Add dyn_meta to your Gemfile
12
-
13
- gem 'dyn_meta'
14
-
15
- Install the gem
16
-
17
- bundle install
18
-
19
- == Usage
20
-
21
- Set up your translations as follows:
22
-
23
- en:
24
- meta:
25
- <meta key pluralized>:
26
- <controller>:
27
- <action>:
28
- <id>: "Some meta value"
29
-
30
- For example:
31
-
32
- en:
33
- meta:
34
- titles:
35
- users:
36
- new: "Create Your Account"
37
- edit: "Update Your Account"
38
-
39
- You usually won't go down to the _id_ level but occasionally it's useful:
40
-
41
- en:
42
- meta:
43
- titles:
44
- pages:
45
- show:
46
- tos: "Terms of Service"
47
- pp: "Privacy Policy"
48
- about: "About My Site"
49
-
50
- You can define catch-alls via the _default_ key:
51
-
52
- en:
53
- meta:
54
- titles:
55
- default: "My Super Site"
56
- users:
57
- default: "Manage Your Account"
58
- new: "Create Your Account"
59
- edit: "Update Your Account"
60
-
61
-
62
- DynMeta provides one method *meta*. It's both a setter and a getter. Just use the *meta* method in your template:
63
-
64
- <title><%= meta(:title) %></title>
65
- <meta name="description" content="<%= meta(:description) %>" />
66
-
67
- If you'd like to override meta content you can just pass a value to the *meta* method:
68
-
69
- def show
70
- @user = User.find(params[:id])
71
- meta(:title, "#{@user.display_name} :: Profile")
72
- end
73
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.5
Binary file
@@ -1,9 +0,0 @@
1
- Feature: something something
2
- In order to something something
3
- A user something something
4
- something something something
5
-
6
- Scenario: something something
7
- Given inspiration
8
- When I create a sweet new gem
9
- Then everyone should see how awesome I am
@@ -1,13 +0,0 @@
1
- require 'bundler'
2
- begin
3
- Bundler.setup(:default, :development)
4
- rescue Bundler::BundlerError => e
5
- $stderr.puts e.message
6
- $stderr.puts "Run `bundle install` to install missing gems"
7
- exit e.status_code
8
- end
9
-
10
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
11
- require 'dyn_meta'
12
-
13
- require 'rspec/expectations'
@@ -1,33 +0,0 @@
1
- module DynMeta
2
- module ActionController
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- helper_method :meta
7
- end
8
- end
9
-
10
- def meta(name, val = nil)
11
-
12
- in_name = "@meta_#{name}"
13
- return instance_variable_set(in_name, val) if val.present?
14
- return instance_variable_get(in_name) if instance_variable_get(in_name)
15
-
16
- trans = I18n.translate("meta")[name.to_s.pluralize] || {}
17
- hash = trans
18
- [:controller, :action, :id].each do |p|
19
- val = params[p] && hash[params[p].to_s.to_sym] || nil
20
- if val.nil?
21
- return instance_variable_set(in_name, hash[:default] || trans[:default] || nil)
22
- elsif val.is_a?(Hash)
23
- hash = val
24
- else
25
- return instance_variable_set(in_name, val)
26
- end
27
- end
28
- end
29
-
30
- end
31
- end
32
-
33
- ::ActionController::Base.send(:include, ::DynMeta::ActionController)
@@ -1,8 +0,0 @@
1
- en:
2
- foo: bar
3
- meta:
4
- titles:
5
- default: "My Great Startup Idea"
6
- users:
7
- default: "Users, this is for you"
8
- edit: "Update your account"