seory 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +42 -41
- data/lib/seory/rails_helper.rb +1 -1
- data/lib/seory/repository.rb +3 -3
- data/lib/seory/runtime.rb +9 -4
- data/lib/seory/version.rb +1 -1
- data/spec/seory/dsl_spec.rb +1 -1
- data/spec/seory/rails_helper_spec.rb +11 -5
- data/spec/seory/repository_spec.rb +2 -2
- data/spec/seory/runtime_spec.rb +12 -1
- data/spec/support/testing_dsl.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89f54528e92f65e0f2bde744dd32012ecc49ab11
|
4
|
+
data.tar.gz: b80835f02bfd2753c398454b408de843b0bf4f0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f2eef6b3801bdafbac1a991cdcbacd20c3ca65efeee290550e9bbebfdbda980f90eea6a1becf7445eb92fd490e299de9f2e35b79015e11017a2945d1dd5ee35
|
7
|
+
data.tar.gz: 43b63992a32409aaa0d5005a460df1e9398d3b9a3c8ad58fd557270faef98aaa9e99d24b255c46f0189cf418c50edecaf3ca57ac5215bfbe8ace41ff955a8366
|
data/README.md
CHANGED
@@ -21,64 +21,65 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
Specify SEO content as ruby code. For example, `config/
|
24
|
+
Specify SEO content as ruby code. For example, `config/seory/*.rb`
|
25
25
|
|
26
26
|
```ruby
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
# config/seory/products.rb
|
28
|
+
Seory.seo_content 'products' do
|
29
|
+
# Specify SEO content based on `controller#action` rule
|
30
|
+
match *%w[products#popular products#new_release] do
|
31
|
+
title 'Great products | My Great Site[MGS]'
|
32
|
+
meta_description 'A lot of great products'
|
31
33
|
|
32
|
-
|
34
|
+
meta_keywords %w[Software Internet Service].join(',')
|
33
35
|
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
# Can contain dynamic content based on controller using assigned ivar
|
38
|
-
match slug('brands#show') do
|
39
|
-
title { assigns(:brand).name }
|
40
|
-
end
|
36
|
+
h1 'Most popular products'
|
37
|
+
end
|
41
38
|
|
42
|
-
#
|
43
|
-
match
|
44
|
-
|
45
|
-
end
|
39
|
+
# Can contain dynamic content based on controller using assigned ivar
|
40
|
+
match slug('products#show') do
|
41
|
+
assign_reader :product
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
meta_keywords do
|
50
|
-
search = assigns(:search_object)
|
43
|
+
title { product.name }
|
44
|
+
end
|
51
45
|
|
52
|
-
|
46
|
+
# Match with request fullpath
|
47
|
+
match path('/products/special-product') do
|
48
|
+
title 'Special Product Detail'
|
53
49
|
end
|
54
|
-
end
|
55
50
|
|
56
|
-
#
|
57
|
-
match
|
58
|
-
|
51
|
+
# Custom lookup rule with controller
|
52
|
+
match(->(controller) { controller.params[:page].to_i == 1 }) do
|
53
|
+
meta_keywords do
|
54
|
+
search = assigns(:search_object)
|
59
55
|
|
60
|
-
|
61
|
-
|
56
|
+
# do something
|
57
|
+
end
|
58
|
+
end
|
62
59
|
|
63
|
-
|
64
|
-
|
60
|
+
# Use custom word part
|
61
|
+
match slug('products#index') do
|
62
|
+
misc(:page_name) { "#{controller.params[:page].to_i} page | Good products") }
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
h1 { I18n.t("#{controller_name}.h1", scope: 'label.misc_pages' }
|
69
|
-
end
|
70
|
-
```
|
64
|
+
title :page_name
|
65
|
+
h1 :page_name
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
meta_description { "Page for #{misc(:page_name)}" }
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
75
71
|
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
# config/seory/default.rb
|
73
|
+
Seory.seo_content 'default' do
|
74
|
+
default do
|
75
|
+
title 'My Great Service'
|
76
|
+
h1 { I18n.t("#{controller_name}.h1", scope: 'label.misc_pages' }
|
77
|
+
end
|
79
78
|
end
|
80
79
|
```
|
81
80
|
|
81
|
+
Then we can use seory in your application.
|
82
|
+
|
82
83
|
```haml
|
83
84
|
%html
|
84
85
|
%head
|
data/lib/seory/rails_helper.rb
CHANGED
data/lib/seory/repository.rb
CHANGED
@@ -24,10 +24,10 @@ module Seory
|
|
24
24
|
clear_page_order_pre_calculation!
|
25
25
|
end
|
26
26
|
|
27
|
-
def lookup(
|
28
|
-
page = pre_orderd_pages.detect {|pg| pg.match?(controller) } || default
|
27
|
+
def lookup(view_context)
|
28
|
+
page = pre_orderd_pages.detect {|pg| pg.match?(view_context.controller) } || default
|
29
29
|
|
30
|
-
Seory::Runtime.new(page,
|
30
|
+
Seory::Runtime.new(page, view_context, default).tap do |runtime|
|
31
31
|
runtime.extend helper if helper
|
32
32
|
end
|
33
33
|
end
|
data/lib/seory/runtime.rb
CHANGED
@@ -2,26 +2,31 @@ require 'seory'
|
|
2
2
|
|
3
3
|
module Seory
|
4
4
|
class Runtime
|
5
|
+
delegate :controller, to: '@view_context'
|
5
6
|
delegate :action_name, to: :controller
|
6
7
|
|
7
|
-
attr_reader :page_contents
|
8
|
+
attr_reader :page_contents
|
8
9
|
|
9
|
-
def initialize(page_contents,
|
10
|
+
def initialize(page_contents, view_context, fallback = nil)
|
10
11
|
@page_contents = page_contents
|
11
|
-
@
|
12
|
+
@view_context = view_context
|
12
13
|
@fallback = fallback
|
13
14
|
|
14
15
|
extend build_assign_accessor_module(@page_contents.assign_name_accessors)
|
15
16
|
end
|
16
17
|
|
17
18
|
def assigns(name)
|
18
|
-
|
19
|
+
controller.view_assigns[name.to_s]
|
19
20
|
end
|
20
21
|
|
21
22
|
def misc(name)
|
22
23
|
calculate_content_for(name)
|
23
24
|
end
|
24
25
|
|
26
|
+
def helper
|
27
|
+
@view_context
|
28
|
+
end
|
29
|
+
|
25
30
|
Seory::CONTENTS.each do |name|
|
26
31
|
define_method(name) { misc(name) }
|
27
32
|
end
|
data/lib/seory/version.rb
CHANGED
data/spec/seory/dsl_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'seory/dsl'
|
3
3
|
|
4
4
|
describe Seory::Dsl do
|
5
|
-
subject(:seory) { seory_class.lookup(controller) }
|
5
|
+
subject(:seory) { seory_class.lookup(Seory::ViewContextDouble.new(controller)) }
|
6
6
|
|
7
7
|
context 'with traditional syntax' do
|
8
8
|
let(:seory_class) { Object.new.extend(Seory::Dsl) }
|
@@ -6,6 +6,8 @@ describe Seory::RailsHelper do
|
|
6
6
|
Seory.seo_content 'products' do
|
7
7
|
match slug('products#index') do
|
8
8
|
title 'Product index'
|
9
|
+
|
10
|
+
og_image_url { helper.image_url('top-logo.png') }
|
9
11
|
end
|
10
12
|
|
11
13
|
default do
|
@@ -27,22 +29,26 @@ describe Seory::RailsHelper do
|
|
27
29
|
end
|
28
30
|
|
29
31
|
context 'GET /products' do
|
30
|
-
let(:context)
|
31
|
-
|
32
|
+
let(:context) { view_context_double('products#index') }
|
33
|
+
|
34
|
+
before do
|
35
|
+
allow(context).to receive(:image_url) {|img| "http://example.com/assets/#{img}?12345" }
|
32
36
|
end
|
33
37
|
|
34
38
|
specify do
|
35
39
|
expect(context.seory.title).to eq 'Product index'
|
36
40
|
end
|
41
|
+
|
42
|
+
specify do
|
43
|
+
expect(context.seory.og_image_url).to eq 'http://example.com/assets/top-logo.png?12345'
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
context 'GET /products/a-computer/reviews' do
|
40
48
|
let(:context) do
|
41
|
-
|
49
|
+
view_context_double('products/reviews#index') do
|
42
50
|
@product = OpenStruct.new(name: 'a-computer')
|
43
51
|
end
|
44
|
-
|
45
|
-
Seory::ViewContextDouble.new(controller)
|
46
52
|
end
|
47
53
|
|
48
54
|
specify do
|
@@ -18,7 +18,7 @@ describe Seory::Repository do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def title_for(*args)
|
21
|
-
repository.lookup(
|
21
|
+
repository.lookup(view_context_double(*args)).title
|
22
22
|
end
|
23
23
|
|
24
24
|
def page_group(name, title = name)
|
@@ -95,7 +95,7 @@ describe Seory::Repository do
|
|
95
95
|
expect {
|
96
96
|
repository << describe_page_group('duplicate default') { default { title 'duplicate default' } }
|
97
97
|
|
98
|
-
repository.lookup(
|
98
|
+
repository.lookup(view_context_double('hi#index'))
|
99
99
|
}.to raise_error(Seory::DuplicateDefault)
|
100
100
|
end
|
101
101
|
end
|
data/spec/seory/runtime_spec.rb
CHANGED
@@ -4,7 +4,8 @@ require 'seory/page'
|
|
4
4
|
|
5
5
|
describe Seory::Runtime do
|
6
6
|
let(:seory) do
|
7
|
-
|
7
|
+
view_context = double('context', controller: controller)
|
8
|
+
Seory::Runtime.new(page_contents, view_context)
|
8
9
|
end
|
9
10
|
|
10
11
|
let(:controller) { double('controller') }
|
@@ -88,4 +89,14 @@ describe Seory::Runtime do
|
|
88
89
|
expect(seory.h1).to eq 'A title'
|
89
90
|
end
|
90
91
|
end
|
92
|
+
|
93
|
+
context 'Can call view_context methods' do
|
94
|
+
before do
|
95
|
+
page_contents.define(:title) { "#{helper.number_with_delimiter(10_000)} items" }
|
96
|
+
|
97
|
+
expect(seory.helper).to receive(:number_with_delimiter).with(10_000) { '10,000' }
|
98
|
+
end
|
99
|
+
|
100
|
+
specify { expect(seory.title).to eq '10,000 items' }
|
101
|
+
end
|
91
102
|
end
|
data/spec/support/testing_dsl.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- moro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|