metazilla 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +101 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/metazilla/translator.rb +47 -0
- data/lib/metazilla/version.rb +3 -0
- data/lib/metazilla/view_helper.rb +51 -0
- data/lib/metazilla.rb +8 -0
- data/metazilla.gemspec +26 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c615ac46c3e656c14e6abeb9a9b42fdedfc3495d
|
4
|
+
data.tar.gz: 56469a5358933b69a2dc68047641b8dd8581a8fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85dc9c95017e50243ec48ee35e8888a9953e5c29e68947c4e3942c6c2cc695426df48a6a8e41967bc9707846fbfd55df3de229ec25bb32a25b766167e4a6adb7
|
7
|
+
data.tar.gz: d688b119d24165c5350a12adc32146955b049fe746d37a1e43bfc593cb7d6117fc3193f4a3fe8a177e5864748b497fd4d0d3c252ea8d1db34e12595fe3754644
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 bsboris
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Metazilla
|
2
|
+
|
3
|
+
Simple gem to deal with titles and meta tags for Rails 3+.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "metazilla", "~> 1.0"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Title
|
18
|
+
|
19
|
+
`title "My page"` to set page title.
|
20
|
+
|
21
|
+
`title` to get page title.
|
22
|
+
|
23
|
+
`app_title "My app"` to set application title.
|
24
|
+
|
25
|
+
`app title` to get application title.
|
26
|
+
|
27
|
+
`full_title` generates full title (page and app title joined).
|
28
|
+
|
29
|
+
`title_tag` generates `<title>` tag with full title. Place this in your layout.
|
30
|
+
|
31
|
+
### Meta tags
|
32
|
+
|
33
|
+
`meta :description, "My app description"` to set meta tag.
|
34
|
+
|
35
|
+
`meta :description` to get meta tag.
|
36
|
+
|
37
|
+
`meta_tag :description` generates `<meta>` tag. Place this in your layout.
|
38
|
+
|
39
|
+
### I18n
|
40
|
+
|
41
|
+
Metazilla fully supports Rails built-in i18n engine.
|
42
|
+
|
43
|
+
Place your titles and meta tags in the en.yml file:
|
44
|
+
|
45
|
+
en:
|
46
|
+
app: My app
|
47
|
+
meta:
|
48
|
+
description: My app.
|
49
|
+
posts:
|
50
|
+
title: Posts
|
51
|
+
index:
|
52
|
+
title: Posts list
|
53
|
+
meta:
|
54
|
+
description: My posts list.
|
55
|
+
|
56
|
+
### Passing variables to translations
|
57
|
+
|
58
|
+
All defined instance variables passed to translations.
|
59
|
+
|
60
|
+
YAML:
|
61
|
+
|
62
|
+
en:
|
63
|
+
titles:
|
64
|
+
users:
|
65
|
+
show: User: %{user}
|
66
|
+
|
67
|
+
Model:
|
68
|
+
|
69
|
+
class User < ActiveRecord::Base
|
70
|
+
def to_s
|
71
|
+
user.full_name
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Controller:
|
76
|
+
|
77
|
+
def show
|
78
|
+
@user = User.find(params[:id])
|
79
|
+
end
|
80
|
+
|
81
|
+
View:
|
82
|
+
|
83
|
+
title # => User: John Doe
|
84
|
+
|
85
|
+
|
86
|
+
### Namespacing
|
87
|
+
|
88
|
+
Namespaced controllers/views are supported, so you can have separate set of titles for different parts of your application.
|
89
|
+
|
90
|
+
en:
|
91
|
+
app: My app
|
92
|
+
admin:
|
93
|
+
app: My admin panel
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork it
|
98
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
99
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
100
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
101
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "metazilla"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Metazilla
|
2
|
+
class Translator
|
3
|
+
attr_reader :namespace, :controller, :action, :context
|
4
|
+
|
5
|
+
def initialize(controller_path, action, context = {})
|
6
|
+
@namespace, @controller = parse_namespace_and_controller(controller_path)
|
7
|
+
@action = action.to_s.freeze
|
8
|
+
@context = context
|
9
|
+
end
|
10
|
+
|
11
|
+
def lookup(key)
|
12
|
+
lookup_recursively key, namespace
|
13
|
+
end
|
14
|
+
|
15
|
+
def lookup_for_current_path(key)
|
16
|
+
lookup_recursively(key, [namespace, controller, action].flatten)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse_namespace_and_controller(controller_path)
|
22
|
+
parts = controller_path.to_s.split("/")
|
23
|
+
if parts.size > 1
|
24
|
+
[parts[0...-1], parts[-1]]
|
25
|
+
else
|
26
|
+
[[], parts[0]]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def lookup_recursively(key, namespace)
|
31
|
+
namespace.size.downto(0).each do |depth|
|
32
|
+
result = lookup_in_namespace(key, namespace.first(depth))
|
33
|
+
return result if result
|
34
|
+
end
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def lookup_in_namespace(key, namespace = [])
|
39
|
+
t_key = [namespace, key].flatten.compact.join('.')
|
40
|
+
i18n_set?(t_key) ? I18n.t(t_key, context) : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def i18n_set?(key)
|
44
|
+
I18n.t(key, raise: true) rescue false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "metazilla/translator"
|
2
|
+
|
3
|
+
module Metazilla
|
4
|
+
module ViewHelper
|
5
|
+
def title(value = nil)
|
6
|
+
if value.present?
|
7
|
+
_meta_store[:page_title] = value
|
8
|
+
else
|
9
|
+
_meta_store[:page_title] || _translator.lookup_for_current_path(:title)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def app_title(value = nil)
|
14
|
+
if value.present?
|
15
|
+
_meta_store[:app_title] = value
|
16
|
+
else
|
17
|
+
_meta_store[:app_title] || _translator.lookup(:app)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def title_tag
|
22
|
+
content_tag :title, full_title
|
23
|
+
end
|
24
|
+
|
25
|
+
def full_title
|
26
|
+
[title, app_title].flatten.compact.join(" | ")
|
27
|
+
end
|
28
|
+
|
29
|
+
def meta(name, content = nil)
|
30
|
+
if content.present?
|
31
|
+
_meta_store[name] = content
|
32
|
+
else
|
33
|
+
_meta_store[name] || _translator.lookup_for_current_path(:"meta.#{name}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def meta_tag(name)
|
38
|
+
tag :meta, name: name, content: meta(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def _meta_store
|
44
|
+
@_meta_store ||= {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def _translator
|
48
|
+
@_translator ||= Translator.new(controller_path, action_name, controller.view_assigns.symbolize_keys)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/metazilla.rb
ADDED
data/metazilla.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'metazilla/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "metazilla"
|
8
|
+
spec.version = Metazilla::VERSION
|
9
|
+
spec.authors = ["Eugene Likholetov"]
|
10
|
+
spec.email = ["bsboris@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple metatags and page titles for Rails.}
|
13
|
+
spec.description = %q{Simple metatags and page titles for Rails.}
|
14
|
+
spec.homepage = "https://github.com/bsboris/metazilla"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "actionview", ">= 3.0.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metazilla
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Likholetov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionview
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.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: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Simple metatags and page titles for Rails.
|
56
|
+
email:
|
57
|
+
- bsboris@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/metazilla.rb
|
71
|
+
- lib/metazilla/translator.rb
|
72
|
+
- lib/metazilla/version.rb
|
73
|
+
- lib/metazilla/view_helper.rb
|
74
|
+
- metazilla.gemspec
|
75
|
+
homepage: https://github.com/bsboris/metazilla
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Simple metatags and page titles for Rails.
|
99
|
+
test_files: []
|