snipp 0.0.6 → 0.1.0
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 +56 -4
- data/app/views/layouts/application.html.erb +1 -1
- data/app/views/snipp/breadcrumb.html.erb +1 -1
- data/app/views/snipp/geo.html.erb +1 -1
- data/app/views/snipp/html.html.erb +10 -0
- data/app/views/snipp/index.html.erb +1 -1
- data/build_gem.sh +48 -0
- data/config/locales/snipp.yml +15 -0
- data/lib/snipp.rb +1 -0
- data/lib/snipp/config.rb +17 -3
- data/lib/snipp/helpers/action_view_extension.rb +4 -0
- data/lib/snipp/markups/html.rb +92 -0
- data/lib/snipp/version.rb +1 -1
- data/snipp.gemspec +2 -2
- data/spec/fake_rails.rb +4 -1
- data/spec/snipp/markups/html_spec.rb +37 -0
- data/spec/snipp_spec.rb +1 -1
- metadata +10 -6
- data/deploy_gem.sh +0 -34
data/README.md
CHANGED
@@ -3,7 +3,11 @@
|
|
3
3
|
[](https://coveralls.io/r/yulii/snipp)
|
4
4
|
[](https://travis-ci.org/yulii/snipp)
|
5
5
|
|
6
|
-
|
6
|
+
Search Engine Optimization (SEO) helpers for Ruby on Rails
|
7
|
+
|
8
|
+
## Supported
|
9
|
+
- HTML meta tags
|
10
|
+
- Rich snippets and structured data
|
7
11
|
|
8
12
|
## Installation
|
9
13
|
|
@@ -21,6 +25,54 @@ Or install it yourself as:
|
|
21
25
|
$ gem install snipp
|
22
26
|
```
|
23
27
|
## Usage
|
28
|
+
### HTML Meta Tags
|
29
|
+
Call `html_meta_tags` in an view template
|
30
|
+
```html+ruby
|
31
|
+
<!DOCTYPE html>
|
32
|
+
<html>
|
33
|
+
<head>
|
34
|
+
<meta charset='utf-8'>
|
35
|
+
<%= html_meta_tags %>
|
36
|
+
<%= stylesheet_link_tag :all %>
|
37
|
+
<%= javascript_include_tag :defaults %>
|
38
|
+
<%= csrf_meta_tag %>
|
39
|
+
...
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Contents
|
43
|
+
direct set
|
44
|
+
```ruby
|
45
|
+
set_html_meta({
|
46
|
+
title: "Page Title",
|
47
|
+
description: "Page Description",
|
48
|
+
og: {
|
49
|
+
title: "Title for Social Media"
|
50
|
+
},
|
51
|
+
link: {
|
52
|
+
canonical: "https://github.com/yulii/snipp"
|
53
|
+
}
|
54
|
+
}, {
|
55
|
+
arg: "Option Values for I18n",
|
56
|
+
page: params[:page]
|
57
|
+
})
|
58
|
+
```
|
59
|
+
|
60
|
+
controller/action
|
61
|
+
```ruby
|
62
|
+
I18n.t(:title, scope: [:views, params[:controller], params[:action], :meta])
|
63
|
+
```
|
64
|
+
|
65
|
+
default values
|
66
|
+
```ruby
|
67
|
+
I18n.t(:title, scope: [:default, :meta])
|
68
|
+
```
|
69
|
+
|
70
|
+
For more information
|
71
|
+
- read erb files in [`app/view/snipp/html.html.erb`](https://github.com/yulii/snipp/tree/master/app/views/snipp)
|
72
|
+
- read locale files in [`config/locales`](https://github.com/yulii/snipp/tree/master/app/views/snipp)
|
73
|
+
|
74
|
+
|
75
|
+
### Rich Snippets
|
24
76
|
Call `item_tag` like `content_tag`
|
25
77
|
|
26
78
|
```html+ruby
|
@@ -47,7 +99,7 @@ This would output
|
|
47
99
|
</div>
|
48
100
|
```
|
49
101
|
|
50
|
-
|
102
|
+
#### Breadcrumbs
|
51
103
|
1. Define naming routes. You can specify a name for any route using the :as option in Rails Application.
|
52
104
|
2. Setup the Rails Application for Internationalization (i18n).
|
53
105
|
3. Call `breadcrumb` method.
|
@@ -68,14 +120,14 @@ en:
|
|
68
120
|
Link to `root_path`, `food_path`, `food_fruit_path`.
|
69
121
|
|
70
122
|
|
71
|
-
|
123
|
+
##### Change the separator
|
72
124
|
Use the :s or :separator option.
|
73
125
|
|
74
126
|
```html+ruby
|
75
127
|
<%= breadcrumb [:index, :foods, :fruits], s: "/" %>
|
76
128
|
```
|
77
129
|
|
78
|
-
|
130
|
+
##### Use variables and Customize labels
|
79
131
|
|
80
132
|
```html+ruby
|
81
133
|
<%= breadcrumb [:index, :foods, :fruits, { path: fruits_color_path('Red'), label: 'Red' }, { path: food_path(color: 'Red', name: 'Apple'), label: 'Apple' }], s: "/" %>
|
data/build_gem.sh
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
LIB_NAME="snipp"
|
3
|
+
if [ $# -ne 2 ]
|
4
|
+
then
|
5
|
+
echo "Usage: $0 {version} {target}"
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
GEMSPEC="${LIB_NAME}.gemspec"
|
9
|
+
PKG_FILE="${LIB_NAME}-$1.gem"
|
10
|
+
|
11
|
+
echo "[RUN] gem install"
|
12
|
+
bundle install
|
13
|
+
echo "[RUN] rake"
|
14
|
+
bundle exec rake
|
15
|
+
|
16
|
+
if [ $? -eq 1 ]
|
17
|
+
then
|
18
|
+
exit 1
|
19
|
+
fi
|
20
|
+
echo "[RUN] gem build ${GEMSPEC}"
|
21
|
+
gem build ${GEMSPEC}
|
22
|
+
if [ $? -eq 1 ]
|
23
|
+
then
|
24
|
+
exit 1
|
25
|
+
fi
|
26
|
+
|
27
|
+
echo "[RUN] mv ${PKG_FILE} pkg/"
|
28
|
+
mv ${PKG_FILE} ./pkg
|
29
|
+
|
30
|
+
case "$2" in
|
31
|
+
"install")
|
32
|
+
echo "[RUN] rake install pkg/${PKG_FILE}"
|
33
|
+
bundle exec rake install --trace
|
34
|
+
;;
|
35
|
+
"deploy")
|
36
|
+
echo "[RUN] gem push pkg/${PKG_FILE}"
|
37
|
+
gem push pkg/${PKG_FILE}
|
38
|
+
|
39
|
+
echo "[RUN] git tag -a version-$1"
|
40
|
+
git tag -a version-$1 -m ""
|
41
|
+
git push --tags
|
42
|
+
;;
|
43
|
+
*)
|
44
|
+
echo "FATAL: invalid target"
|
45
|
+
exit 1
|
46
|
+
;;
|
47
|
+
esac
|
48
|
+
|
data/config/locales/snipp.yml
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
en:
|
2
|
+
default:
|
3
|
+
meta:
|
4
|
+
title: "Default Title"
|
5
|
+
description: "Default Description"
|
6
|
+
keywords: "Default Description"
|
7
|
+
|
2
8
|
views:
|
9
|
+
snipp:
|
10
|
+
html:
|
11
|
+
meta:
|
12
|
+
title: "HTML Title -- %{value}"
|
13
|
+
breadcrumb:
|
14
|
+
meta:
|
15
|
+
title: "Snipp"
|
16
|
+
|
3
17
|
breadcrumb:
|
4
18
|
# Sample
|
5
19
|
index: "Top"
|
@@ -7,3 +21,4 @@ en:
|
|
7
21
|
fruits: "Fruits"
|
8
22
|
fruits_color: "%{color}"
|
9
23
|
food: "%{name}"
|
24
|
+
|
data/lib/snipp.rb
CHANGED
data/lib/snipp/config.rb
CHANGED
@@ -12,8 +12,7 @@ module Snipp
|
|
12
12
|
|
13
13
|
class Configuration #:nodoc:
|
14
14
|
include ActiveSupport::Configurable
|
15
|
-
config_accessor :root_url
|
16
|
-
config_accessor :markup
|
15
|
+
config_accessor :root_url, :markup, :html_meta_tags
|
17
16
|
|
18
17
|
def param_name
|
19
18
|
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
@@ -26,6 +25,21 @@ module Snipp
|
|
26
25
|
end
|
27
26
|
|
28
27
|
configure do |config|
|
29
|
-
config.markup
|
28
|
+
config.markup = :microdata
|
29
|
+
config.html_meta_tags = {
|
30
|
+
title: '',
|
31
|
+
description: '',
|
32
|
+
keywords: '',
|
33
|
+
og: {
|
34
|
+
site_name: '',
|
35
|
+
type: 'article',
|
36
|
+
title: '',
|
37
|
+
description: '',
|
38
|
+
image: ''
|
39
|
+
},
|
40
|
+
author: '',
|
41
|
+
robots: ['index,follow', 'noodp', 'noydir'],
|
42
|
+
viewport: 'width=device-width'
|
43
|
+
}
|
30
44
|
end
|
31
45
|
end
|
@@ -2,6 +2,10 @@ module Snipp
|
|
2
2
|
module ActionViewExtension
|
3
3
|
|
4
4
|
def self.included(base)
|
5
|
+
# Include HTML meta module
|
6
|
+
base.send :include, Snipp::Markup::Html
|
7
|
+
|
8
|
+
# Include markup module
|
5
9
|
name = "#{Snipp.config.markup}".camelize
|
6
10
|
raise NotImplementedError, "#{name} is invalid. Specify correct Snipp.config.markup." unless Snipp::Markup.const_defined? name
|
7
11
|
base.send :include, Snipp::Markup.const_get(name)
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Snipp
|
2
|
+
module Markup
|
3
|
+
module Html
|
4
|
+
|
5
|
+
def set_html_meta args, options = {}
|
6
|
+
i18n_options = {
|
7
|
+
scope: [:views, params[:controller], params[:action], :meta],
|
8
|
+
default_scope: [:default, :meta],
|
9
|
+
default: ''
|
10
|
+
}.merge(options)
|
11
|
+
|
12
|
+
link = args.delete(:link)
|
13
|
+
html_meta.merge!(link: link) if link
|
14
|
+
|
15
|
+
Snipp.config.html_meta_tags.merge(args).each do |name, content|
|
16
|
+
value = html_meta_contents(name, content, i18n_options)
|
17
|
+
html_meta[name] = value unless value.blank?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def html_meta_tags
|
22
|
+
result = ''
|
23
|
+
set_html_meta({}) if html_meta.empty?
|
24
|
+
meta_link = html_meta.delete(:link)||{}
|
25
|
+
|
26
|
+
# TDK
|
27
|
+
title = html_meta.delete(:title)
|
28
|
+
unless title.blank?
|
29
|
+
result << content_tag(:title, title)
|
30
|
+
result << tag(:meta, name: :title, content: title)
|
31
|
+
end
|
32
|
+
|
33
|
+
html_meta.each do |name, content|
|
34
|
+
if content.is_a?(Hash)
|
35
|
+
result << build_meta_property_tags(name, content)
|
36
|
+
else
|
37
|
+
Array(content).each do |c|
|
38
|
+
result << tag(:meta, name: name, content: c) unless c.blank?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
meta_link.each do |rel, href|
|
44
|
+
result << tag(:link, :rel => rel, :href => href) unless href.blank?
|
45
|
+
end
|
46
|
+
|
47
|
+
result.blank? ? nil : result.html_safe
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def html_meta_contents property, content, options = {}
|
52
|
+
result = {}
|
53
|
+
if content.is_a?(Hash)
|
54
|
+
content.each do |key, value|
|
55
|
+
options = options.dup
|
56
|
+
options[:scope] << property
|
57
|
+
options[:default_scope] << property
|
58
|
+
result[key] = html_meta_contents(key, value, options)
|
59
|
+
end
|
60
|
+
else
|
61
|
+
result = content
|
62
|
+
result = I18n.t(property, options) if result.blank?
|
63
|
+
result = I18n.t(property, scope: options[:default_scope], default: '') if result.blank?
|
64
|
+
end
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_meta_property_tags(property, content)
|
69
|
+
result = ''
|
70
|
+
if content.is_a?(Hash)
|
71
|
+
content.each do |key, value|
|
72
|
+
result << build_meta_property_tags("#{property}:#{key}", value)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
Array(content).each do |c|
|
76
|
+
if c.is_a?(Hash)
|
77
|
+
result << build_meta_property_tags(property, c)
|
78
|
+
else
|
79
|
+
result << tag(:meta, :property => "#{property}", :content => c) unless c.blank?
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
result
|
84
|
+
end
|
85
|
+
|
86
|
+
def html_meta
|
87
|
+
@html_meta ||= {}
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/snipp/version.rb
CHANGED
data/snipp.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Snipp::VERSION
|
9
9
|
gem.authors = ["yulii"]
|
10
10
|
gem.email = ["yuliinfo@gmail.com"]
|
11
|
-
gem.description = %q{
|
11
|
+
gem.description = %q{Search Engine Optimization (SEO) helpers for Ruby on Rails}
|
12
12
|
gem.summary = %q{Let search engines understand the content on your website}
|
13
13
|
gem.homepage = "https://github.com/yulii/snipp"
|
14
14
|
|
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency
|
20
|
+
gem.add_dependency 'rails', '>= 3.2.11'
|
21
21
|
end
|
data/spec/fake_rails.rb
CHANGED
@@ -11,13 +11,16 @@ end
|
|
11
11
|
app.initialize!
|
12
12
|
|
13
13
|
# routing
|
14
|
-
ITEMTYPES = [:index, :breadcrumb, :geo]
|
14
|
+
ITEMTYPES = [:index, :html, :breadcrumb, :geo]
|
15
15
|
app.routes.draw do
|
16
16
|
|
17
17
|
ITEMTYPES.each do |e|
|
18
18
|
get "/#{e}" => "snipp##{e}", as: e
|
19
19
|
end
|
20
20
|
|
21
|
+
# HTML Meta Tags
|
22
|
+
get "/html" => "snipp#html", as: :html
|
23
|
+
|
21
24
|
# for Breadcumb
|
22
25
|
get "/foods" => "snipp#breadcrumb", as: :foods
|
23
26
|
get "/foods/fruits" => "snipp#breadcrumb", as: :fruits
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
class Snipp::Markup::Html::Spec
|
5
|
+
|
6
|
+
DEFAULT_SCOPE = [:default, :meta]
|
7
|
+
PAGE_SCOPE = [:views, :snipp, :html, :meta]
|
8
|
+
|
9
|
+
META = [
|
10
|
+
{ id: "TDK", title: I18n.t(:title, scope: PAGE_SCOPE, value: "Embedding Values"), description: I18n.t(:description, scope: DEFAULT_SCOPE), keywords: I18n.t(:keywords, scope: DEFAULT_SCOPE) }
|
11
|
+
]
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Snipp::Markup::Html do
|
16
|
+
|
17
|
+
before do
|
18
|
+
Snipp::Hooks.init
|
19
|
+
visit "/html"
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "HTML Meta Tags" do
|
23
|
+
|
24
|
+
Snipp::Markup::Html::Spec::META.each do |e|
|
25
|
+
id = e.delete(:id)
|
26
|
+
context id do
|
27
|
+
e.each do |key, value|
|
28
|
+
it "should have a `#{key}` tag" do
|
29
|
+
expect(page).to have_selector("meta[name=\"#{key}\"][content=\"#{value}\"]", count: 1)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/snipp_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snipp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,14 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 3.2.11
|
22
22
|
type: :runtime
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 3.2.11
|
30
|
-
description:
|
30
|
+
description: Search Engine Optimization (SEO) helpers for Ruby on Rails
|
31
31
|
email:
|
32
32
|
- yuliinfo@gmail.com
|
33
33
|
executables: []
|
@@ -44,20 +44,23 @@ files:
|
|
44
44
|
- app/views/layouts/application.html.erb
|
45
45
|
- app/views/snipp/breadcrumb.html.erb
|
46
46
|
- app/views/snipp/geo.html.erb
|
47
|
+
- app/views/snipp/html.html.erb
|
47
48
|
- app/views/snipp/index.html.erb
|
49
|
+
- build_gem.sh
|
48
50
|
- config/locales/snipp.yml
|
49
|
-
- deploy_gem.sh
|
50
51
|
- lib/snipp.rb
|
51
52
|
- lib/snipp/config.rb
|
52
53
|
- lib/snipp/engine.rb
|
53
54
|
- lib/snipp/helpers/action_view_extension.rb
|
54
55
|
- lib/snipp/hooks.rb
|
56
|
+
- lib/snipp/markups/html.rb
|
55
57
|
- lib/snipp/markups/microdata.rb
|
56
58
|
- lib/snipp/railtie.rb
|
57
59
|
- lib/snipp/version.rb
|
58
60
|
- snipp.gemspec
|
59
61
|
- spec/fake_rails.rb
|
60
62
|
- spec/snipp/helpers/action_view_extension_spec.rb
|
63
|
+
- spec/snipp/markups/html_spec.rb
|
61
64
|
- spec/snipp/markups/microdata/breadcrumb_spec.rb
|
62
65
|
- spec/snipp/markups/microdata/geo_spec.rb
|
63
66
|
- spec/snipp_spec.rb
|
@@ -89,6 +92,7 @@ summary: Let search engines understand the content on your website
|
|
89
92
|
test_files:
|
90
93
|
- spec/fake_rails.rb
|
91
94
|
- spec/snipp/helpers/action_view_extension_spec.rb
|
95
|
+
- spec/snipp/markups/html_spec.rb
|
92
96
|
- spec/snipp/markups/microdata/breadcrumb_spec.rb
|
93
97
|
- spec/snipp/markups/microdata/geo_spec.rb
|
94
98
|
- spec/snipp_spec.rb
|
data/deploy_gem.sh
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
LIB_NAME="snipp"
|
3
|
-
if [ $# -ne 1 ]
|
4
|
-
then
|
5
|
-
echo "invalid VERSION"
|
6
|
-
exit 1
|
7
|
-
fi
|
8
|
-
GEMSPEC="${LIB_NAME}.gemspec"
|
9
|
-
PKG_FILE="${LIB_NAME}-$1.gem"
|
10
|
-
|
11
|
-
echo "[RUN] gem install"
|
12
|
-
bundle install
|
13
|
-
echo "[RUN] rake"
|
14
|
-
bundle exec rake
|
15
|
-
|
16
|
-
if [ $? -eq 1 ]
|
17
|
-
then
|
18
|
-
exit 1
|
19
|
-
fi
|
20
|
-
echo "[RUN] gem build ${GEMSPEC}"
|
21
|
-
gem build ${GEMSPEC}
|
22
|
-
if [ $? -eq 1 ]
|
23
|
-
then
|
24
|
-
exit 1
|
25
|
-
fi
|
26
|
-
|
27
|
-
echo "[RUN] mv ${PKG_FILE} pkg/"
|
28
|
-
mv ${PKG_FILE} ./pkg
|
29
|
-
echo "[RUN] gem push pkg/${PKG_FILE}"
|
30
|
-
gem push pkg/${PKG_FILE}
|
31
|
-
|
32
|
-
echo "[RUN] git tag -a version-$1"
|
33
|
-
git tag -a version-$1 -m ""
|
34
|
-
git push --tags
|