metas 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/metas.rb +7 -0
- data/lib/metas/controller/change_meta_tags.rb +19 -0
- data/lib/metas/helpers/tags.rb +41 -0
- data/lib/metas/main.rb +53 -0
- data/lib/metas/version.rb +3 -0
- data/metas.gemspec +27 -0
- data/spec/config/metas.yml +10 -0
- data/spec/metas/controller/change_meta_tags_spec.rb +20 -0
- data/spec/metas/helpers/tags_spec.rb +27 -0
- data/spec/metas/main_spec.rb +26 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/dumb_controller.rb +11 -0
- data/spec/support/dummy_controller.rb +20 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e284936f1ed9587cc1c3220db5b48c3891667b2d
|
4
|
+
data.tar.gz: 495175b8f856653b49dfd38636b6527a433ef7ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd89cd8383dad3adeed61e8916d87720913645ecb25fe55f68c5966ae816e40937beb6f0b79594c28a58a2bdaab938236aaab235cbc2634d97405ce33dd8409d
|
7
|
+
data.tar.gz: 17f1d226e4eed45f0d2ae4b81b40d072706df6be8652fbe08c080bb4a71c3c324b88a2303bbd793ab84cd791f31ca9d13d0f4bd2fdfd5e37c141c15cf0a3a0ba
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Metas
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'metas'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install metas
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/metas/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/metas.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Metas
|
2
|
+
module Controller
|
3
|
+
module ChangeMetaTags
|
4
|
+
module InstanceMethods
|
5
|
+
|
6
|
+
def change_meta_tags(&block)
|
7
|
+
self.define_singleton_method(:default_meta_tags) do
|
8
|
+
super().merge(block.call)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined? ActionController::Base
|
18
|
+
ActionController::Base.send :include, Metas::Controller::ChangeMetaTags::InstanceMethods
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
3
|
+
module Metas
|
4
|
+
module Helpers
|
5
|
+
module Tags
|
6
|
+
module InstanceMethods
|
7
|
+
include ActionView::Helpers::TagHelper
|
8
|
+
|
9
|
+
def meta_tags
|
10
|
+
meta_main.normalize.each_with_object([]) do |(tag, values), ary|
|
11
|
+
correct_property = meta_main.options[:irregular][tag] || meta_main.options[:irregular][:default]
|
12
|
+
|
13
|
+
values.each do |attr, content|
|
14
|
+
ary << tag(:meta, { :content => content, correct_property => meta_property(tag, attr) }, true, false)
|
15
|
+
end
|
16
|
+
end.join("\n").html_safe
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_meta(attr)
|
20
|
+
split_attr = attr.split(":")
|
21
|
+
metas = meta_main.normalize.deep_stringify_keys
|
22
|
+
return nil if metas[split_attr[0]].nil?
|
23
|
+
|
24
|
+
metas[split_attr[0]][split_attr[1]]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def meta_property(tag, attr)
|
30
|
+
"#{tag}:#{attr}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def meta_main
|
34
|
+
Metas::Main.new(controller)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
ActionView::Base.send :include, Metas::Helpers::Tags::InstanceMethods
|
data/lib/metas/main.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
|
4
|
+
module Metas
|
5
|
+
class Main
|
6
|
+
attr_reader :controller, :values, :default_values, :options
|
7
|
+
|
8
|
+
def initialize(controller)
|
9
|
+
@controller = controller
|
10
|
+
@values = controller.default_meta_tags
|
11
|
+
@default_values = default_values_social
|
12
|
+
@options = YAML.load_file(Rails.root.join('config/metas.yml')).deep_symbolize_keys[:metas]
|
13
|
+
end
|
14
|
+
|
15
|
+
def normalize
|
16
|
+
ignore_keys = default_values.keys
|
17
|
+
all_tags_included = insert_all(values)
|
18
|
+
|
19
|
+
all_tags_included.each_with_object({}) do |(social, tags), hsh|
|
20
|
+
next if ignore_keys.include?(social)
|
21
|
+
|
22
|
+
hsh[social] = tags
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def default_values_social
|
29
|
+
values.each_with_object({}) do |(key, value), hsh|
|
30
|
+
next if value.kind_of? Hash
|
31
|
+
|
32
|
+
hsh[key] = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def insert_all(meta_tags)
|
37
|
+
meta_tags.each_with_object({}) do |(key, tags), hsh|
|
38
|
+
if tags.kind_of?(Hash)
|
39
|
+
hsh[key] = tags
|
40
|
+
|
41
|
+
default_values.each do |key_social, value_social|
|
42
|
+
next unless options[:same][key_social]
|
43
|
+
correct_key = options[:same][key_social][key].to_sym
|
44
|
+
|
45
|
+
hsh[key][correct_key] = value_social
|
46
|
+
end
|
47
|
+
else
|
48
|
+
hsh[key] = tags
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/metas.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'metas/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "metas"
|
8
|
+
spec.version = Metas::VERSION
|
9
|
+
spec.authors = ["Matheus Cáceres"]
|
10
|
+
spec.email = ["matheuscaceres@gmail.com"]
|
11
|
+
spec.summary = %q{Wouldn't leave their focus, create metas!}
|
12
|
+
spec.description = %q{A gem to create meta tags easy!}
|
13
|
+
spec.homepage = "https://github.com/formaweb/metas"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "actionpack", '>= 4.0.0', '< 4.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake", '~> 10.1.1'
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0.0.beta2"
|
26
|
+
spec.add_development_dependency "capybara", '~> 2.2.0'
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metas::Controller::ChangeMetaTags::InstanceMethods do
|
4
|
+
include Metas::Controller::ChangeMetaTags::InstanceMethods
|
5
|
+
|
6
|
+
describe "#change_meta_tags" do
|
7
|
+
context 'without call change_metas' do
|
8
|
+
subject{ DumbController.new }
|
9
|
+
|
10
|
+
it{ expect(subject.default_meta_tags).to include({ description: "Test" }) }
|
11
|
+
end
|
12
|
+
context 'create default_meta_tags method' do
|
13
|
+
subject{ DumbController.new }
|
14
|
+
before{ subject.change_metas }
|
15
|
+
|
16
|
+
it{ expect(subject.default_meta_tags[:og]).to include({ description: "another test" }) }
|
17
|
+
it{ expect(subject.default_meta_tags[:og]).to_not include({ description: "Test" }) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metas::Helpers::Tags::InstanceMethods do
|
4
|
+
include Capybara::RSpecMatchers
|
5
|
+
include Metas::Helpers::Tags::InstanceMethods
|
6
|
+
|
7
|
+
before do
|
8
|
+
subject.class_eval do
|
9
|
+
def controller
|
10
|
+
DummyController.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#meta_tags" do
|
16
|
+
context "does show all social tags" do
|
17
|
+
it{ expect(meta_tags).to have_selector("meta[property='og:description']", visible: false) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#get_meta" do
|
22
|
+
context "passed in args" do
|
23
|
+
it{ expect(get_meta("og:description")).to eq("Test") }
|
24
|
+
it{ expect(get_meta("twitter:card")).to eq("summary") }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metas::Main do
|
4
|
+
let(:controller){ double("controller", default_meta_tags: DummyController.new.default_meta_tags) }
|
5
|
+
|
6
|
+
subject{ Metas::Main.new(controller) }
|
7
|
+
|
8
|
+
describe "#default_values" do
|
9
|
+
context 'show just values for all social metas' do
|
10
|
+
it{ expect(subject.default_values).to include(description: "Test") }
|
11
|
+
end
|
12
|
+
context 'dont show values for social tags' do
|
13
|
+
it{ expect(subject.default_values).to_not have_key(:og) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#normalize" do
|
18
|
+
context 'hashes for social' do
|
19
|
+
it{ expect(subject.normalize).to have_key(:og) }
|
20
|
+
it{ expect(subject.normalize).to have_key(:twitter) }
|
21
|
+
end
|
22
|
+
context 'without params for all social tags' do
|
23
|
+
it{ expect(subject.normalize).to_not have_key(:description) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class DummyController
|
2
|
+
def default_meta_tags
|
3
|
+
{
|
4
|
+
description: 'Test',
|
5
|
+
keywords: 'test, other, another',
|
6
|
+
title: 'test title',
|
7
|
+
og: {
|
8
|
+
locale: 'pt_BR',
|
9
|
+
type: 'website',
|
10
|
+
site_name: 'Example'
|
11
|
+
},
|
12
|
+
twitter: {
|
13
|
+
card: 'summary',
|
14
|
+
site: '@example',
|
15
|
+
title: 'Example title',
|
16
|
+
domain: 'example.com'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matheus Cáceres
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.5'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 10.1.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 10.1.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 3.0.0.beta2
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.0.0.beta2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: capybara
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.2.0
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.2.0
|
89
|
+
description: A gem to create meta tags easy!
|
90
|
+
email:
|
91
|
+
- matheuscaceres@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".rspec"
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- lib/metas.rb
|
103
|
+
- lib/metas/controller/change_meta_tags.rb
|
104
|
+
- lib/metas/helpers/tags.rb
|
105
|
+
- lib/metas/main.rb
|
106
|
+
- lib/metas/version.rb
|
107
|
+
- metas.gemspec
|
108
|
+
- spec/config/metas.yml
|
109
|
+
- spec/metas/controller/change_meta_tags_spec.rb
|
110
|
+
- spec/metas/helpers/tags_spec.rb
|
111
|
+
- spec/metas/main_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/dumb_controller.rb
|
114
|
+
- spec/support/dummy_controller.rb
|
115
|
+
homepage: https://github.com/formaweb/metas
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.0
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Wouldn't leave their focus, create metas!
|
139
|
+
test_files:
|
140
|
+
- spec/config/metas.yml
|
141
|
+
- spec/metas/controller/change_meta_tags_spec.rb
|
142
|
+
- spec/metas/helpers/tags_spec.rb
|
143
|
+
- spec/metas/main_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
- spec/support/dumb_controller.rb
|
146
|
+
- spec/support/dummy_controller.rb
|