excalibur 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +36 -6
- data/excalibur.gemspec +6 -2
- data/lib/excalibur/decorator.rb +16 -2
- data/lib/excalibur/version.rb +1 -1
- data/lib/excalibur/view_helpers.rb +14 -1
- data/lib/excalibur.rb +1 -3
- data/lib/generators/templates/decorator.rb +2 -1
- data/spec/lib/excalibur/decorator_spec.rb +14 -0
- data/spec/lib/excalibur/view_helper_spec.rb +36 -0
- metadata +7 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e73905a05488d0f31f7bee41eef8755cfd72010
|
|
4
|
+
data.tar.gz: 9d8eb4c51d7996a0faff11fcc93977773b83257e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 631f7546330c3bbefeafb82e8ccf2cd0cc6b7c89b990c6f5c60bcdcb967ea3f9865adcf320bbb5dc9a13d689ed9a04ebdcaa8a9ace15dfd4c951e9946c65ab3c
|
|
7
|
+
data.tar.gz: 9d81f8a6b01e62e92dfe7a982696e7193bfb4655785521ff8173b61e4d2245dd4bb506103791266490f4d5517174ca244360e6f6922be4d1c1f4c0eaff3a2f6b
|
data/README.md
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
# Excalibur
|
|
2
2
|
|
|
3
|
+
[](http://badge.fury.io/rb/excalibur)
|
|
3
4
|
[](https://travis-ci.org/yopefonic/excalibur)
|
|
4
5
|
[](https://codeclimate.com/github/yopefonic/excalibur)
|
|
5
6
|
|
|
6
|
-
Excalibur is a SEO gem for [Ruby on Rails](rubyonrails.org)
|
|
7
|
-
set the title and meta tags for
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
Excalibur is a SEO related gem for [Ruby on Rails](rubyonrails.org) that helps
|
|
8
|
+
you to set the title and meta tags for your site overall and per page in a
|
|
9
|
+
nicely structured and with separated concerns.
|
|
10
|
+
|
|
11
|
+
Setting titles and meta tags for pages can become a hassle when dealing with
|
|
12
|
+
more complex SEO requirements. When adding [OpenGraph](http://ogp.me/),
|
|
13
|
+
[Twitter Cards](https://dev.twitter.com/cards/overview) or
|
|
14
|
+
[schema.org](http://schema.org/docs/gs.html) for Google+ there are a host of
|
|
15
|
+
options that differ from object to object. You could add methods to the object
|
|
16
|
+
model to create these meta tags but that would put rendering concerns into
|
|
17
|
+
model's class. Not an ideal situation. Other option could be to create helper
|
|
18
|
+
methods but as you need to present more than 3 different object they can
|
|
19
|
+
become cluttered, long and unyielding.
|
|
20
|
+
|
|
21
|
+
In comes Excalibur; object presentors that have all the logic per object type,
|
|
22
|
+
convenient helper methods to print them on the page and an application wide
|
|
23
|
+
default configuration.
|
|
12
24
|
|
|
13
25
|
## Installation
|
|
14
26
|
|
|
@@ -78,6 +90,24 @@ context.
|
|
|
78
90
|
entitle @your_object, config: @custom_config
|
|
79
91
|
```
|
|
80
92
|
|
|
93
|
+
### Views without an object
|
|
94
|
+
|
|
95
|
+
In some cases you might not have an object to present. Like when on a
|
|
96
|
+
collection page or when dealing with a static page. There is a helper method
|
|
97
|
+
that allows you to set some custom values. ```quick_set``` takes a couple of
|
|
98
|
+
arguments to set the values of titles, descriptions and meta_tags.
|
|
99
|
+
|
|
100
|
+
These are some examples of what you can set:
|
|
101
|
+
|
|
102
|
+
```erb
|
|
103
|
+
<%
|
|
104
|
+
quick_set :title, :content, :body, 'custom quick set title body'
|
|
105
|
+
quick_set :description, :option, :length, 42
|
|
106
|
+
quick_set :title, :combinator, proc { |obj| custom_code }
|
|
107
|
+
quick_set :meta_tag, :name, :description, 'custom quick set meta tag'
|
|
108
|
+
%>
|
|
109
|
+
```
|
|
110
|
+
|
|
81
111
|
### Decorators
|
|
82
112
|
|
|
83
113
|
The decorators are what turns your object into data that can be used for the
|
data/excalibur.gemspec
CHANGED
|
@@ -8,8 +8,12 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.version = Excalibur::VERSION
|
|
9
9
|
spec.authors = ['Joost Elfering']
|
|
10
10
|
spec.email = ['yopefonic@gmail.com']
|
|
11
|
-
spec.summary = %q{helper gem to set page title and meta tags in a
|
|
12
|
-
|
|
11
|
+
spec.summary = %q{helper gem to set page title and meta tags in a
|
|
12
|
+
rails app}
|
|
13
|
+
spec.description = %q{Excalibur is a SEO related gem for Ruby on Rails
|
|
14
|
+
that helps you to set the title and meta tags for your
|
|
15
|
+
site overall and per page in a nicely structured and
|
|
16
|
+
with separated concerns.}
|
|
13
17
|
spec.homepage = 'https://github.com/yopefonic/excalibur'
|
|
14
18
|
spec.license = 'MIT'
|
|
15
19
|
|
data/lib/excalibur/decorator.rb
CHANGED
|
@@ -21,6 +21,10 @@ module Excalibur
|
|
|
21
21
|
@configuration ||= ::Excalibur.configuration.dup
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# methods:
|
|
25
|
+
# excalibur_set_title_content, excalibur_set_title_option,
|
|
26
|
+
# excalibur_set_title_combinator, excalibur_set_description_content,
|
|
27
|
+
# excalibur_set_description_option, excalibur_set_description_combinator
|
|
24
28
|
def method_missing(meth, *args)
|
|
25
29
|
if meth.to_s =~ /^excalibur_set_(title|description+)_(content|option|combinator+)$/
|
|
26
30
|
configuration.send($1).send("update_#{$2}", *args)
|
|
@@ -48,8 +52,18 @@ module Excalibur
|
|
|
48
52
|
configuration.merge!(config)
|
|
49
53
|
end
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
# methods: render_title, render_description
|
|
56
|
+
def method_missing(meth, *args)
|
|
57
|
+
if meth.to_s =~ /^render_(title|description+)$/
|
|
58
|
+
obj = args.first || self
|
|
59
|
+
subject = configuration.send($1)
|
|
60
|
+
|
|
61
|
+
if subject.present?
|
|
62
|
+
subject.to_s(obj)
|
|
63
|
+
end
|
|
64
|
+
else
|
|
65
|
+
super
|
|
66
|
+
end
|
|
53
67
|
end
|
|
54
68
|
end
|
|
55
69
|
end
|
data/lib/excalibur/version.rb
CHANGED
|
@@ -6,6 +6,19 @@ module Excalibur
|
|
|
6
6
|
@excalibur_subject = excalibur_decorate_subject(object, options)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def quick_set(type, *args)
|
|
10
|
+
case type
|
|
11
|
+
when :title, :description
|
|
12
|
+
section = args.shift
|
|
13
|
+
excalibur_subject.configuration.send(type).send(
|
|
14
|
+
"update_#{section}",
|
|
15
|
+
*args
|
|
16
|
+
)
|
|
17
|
+
when :meta_tag
|
|
18
|
+
excalibur_subject.configuration.set_meta_tag(*args)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
9
22
|
def render_title_tag
|
|
10
23
|
content_tag :title, excalibur_subject.render_title
|
|
11
24
|
end
|
|
@@ -24,7 +37,7 @@ module Excalibur
|
|
|
24
37
|
:meta,
|
|
25
38
|
type_name => type_value,
|
|
26
39
|
content: content
|
|
27
|
-
)
|
|
40
|
+
) unless content.nil?
|
|
28
41
|
end
|
|
29
42
|
end
|
|
30
43
|
end
|
data/lib/excalibur.rb
CHANGED
|
@@ -80,9 +80,7 @@ module Excalibur
|
|
|
80
80
|
def new_default_meta_tags
|
|
81
81
|
::HashWithIndifferentAccess.new(
|
|
82
82
|
name: ::HashWithIndifferentAccess.new(
|
|
83
|
-
description: proc
|
|
84
|
-
obj.configuration.description.to_s(obj)
|
|
85
|
-
end,
|
|
83
|
+
description: proc { |obj| obj.render_description },
|
|
86
84
|
viewport: 'width=device-width, initial-scale=1'
|
|
87
85
|
)
|
|
88
86
|
)
|
|
@@ -71,5 +71,6 @@ class Excalibur::<%= class_name %>Decorator < Excalibur::Decorator
|
|
|
71
71
|
# responsibility. The decorator becomes easier to test and it is also a lot
|
|
72
72
|
# cleaner.
|
|
73
73
|
#
|
|
74
|
-
#
|
|
74
|
+
# read more about how to use decorators with procs properly:
|
|
75
|
+
# https://github.com/yopefonic/excalibur/wiki/Advised-usage-of-proc%27s
|
|
75
76
|
end
|
|
@@ -220,5 +220,19 @@ module Excalibur
|
|
|
220
220
|
end
|
|
221
221
|
end
|
|
222
222
|
end
|
|
223
|
+
|
|
224
|
+
describe '#render_description' do
|
|
225
|
+
let(:obj) { DummyDecorator.decorate(Dummy.new) }
|
|
226
|
+
|
|
227
|
+
context 'when using the default settings' do
|
|
228
|
+
it { expect(obj.render_description).to eq('Excalibur; a worthy title for a gem about titles.') }
|
|
229
|
+
|
|
230
|
+
it 'should call to_s in the title' do
|
|
231
|
+
expect(obj.configuration.description).to receive(:to_s)
|
|
232
|
+
|
|
233
|
+
obj.render_description
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
223
237
|
end
|
|
224
238
|
end
|
|
@@ -31,6 +31,42 @@ module Excalibur
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
describe '#quick_set' do
|
|
35
|
+
it 'should be able to set a meta tag' do
|
|
36
|
+
expect_any_instance_of(Configuration).to receive(:set_meta_tag).with(:name, :description, 'quick set value')
|
|
37
|
+
|
|
38
|
+
helpers.quick_set(:meta_tag, :name, :description, 'quick set value')
|
|
39
|
+
|
|
40
|
+
expect(helpers.instance_variable_get(:@excalibur_subject)).to be_instance_of Decorator
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
[:title, :description].each do |type|
|
|
44
|
+
it "should be able to set #{type} content" do
|
|
45
|
+
expect_any_instance_of(TruncateableContent).to receive(:update_content).with(:body, 'quick set value')
|
|
46
|
+
|
|
47
|
+
helpers.quick_set(type, :content, :body, 'quick set value')
|
|
48
|
+
|
|
49
|
+
expect(helpers.instance_variable_get(:@excalibur_subject)).to be_instance_of Decorator
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should be able to set #{type} options" do
|
|
53
|
+
expect_any_instance_of(TruncateableContent).to receive(:update_option).with(:length, 42)
|
|
54
|
+
|
|
55
|
+
helpers.quick_set(type, :option, :length, 42)
|
|
56
|
+
|
|
57
|
+
expect(helpers.instance_variable_get(:@excalibur_subject)).to be_instance_of Decorator
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should be able to set #{type} combinator" do
|
|
61
|
+
expect_any_instance_of(TruncateableContent).to receive(:update_combinator).with('foobar')
|
|
62
|
+
|
|
63
|
+
helpers.quick_set(type, :combinator, 'foobar')
|
|
64
|
+
|
|
65
|
+
expect(helpers.instance_variable_get(:@excalibur_subject)).to be_instance_of Decorator
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
34
70
|
describe '#render_title_tag' do
|
|
35
71
|
context 'when the configuration is standard' do
|
|
36
72
|
it 'should return a title tag with the default content' do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: excalibur
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joost Elfering
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-10-
|
|
11
|
+
date: 2014-10-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -152,9 +152,11 @@ dependencies:
|
|
|
152
152
|
- - '>='
|
|
153
153
|
- !ruby/object:Gem::Version
|
|
154
154
|
version: 0.10.1
|
|
155
|
-
description:
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
description: |-
|
|
156
|
+
Excalibur is a SEO related gem for Ruby on Rails
|
|
157
|
+
that helps you to set the title and meta tags for your
|
|
158
|
+
site overall and per page in a nicely structured and
|
|
159
|
+
with separated concerns.
|
|
158
160
|
email:
|
|
159
161
|
- yopefonic@gmail.com
|
|
160
162
|
executables: []
|