seory 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 679ed7e93f25e0539660873f3b4ad92d89327082
4
- data.tar.gz: 514f420b0f775555ee3d736120aa7c4a898e1bd1
3
+ metadata.gz: 89f54528e92f65e0f2bde744dd32012ecc49ab11
4
+ data.tar.gz: b80835f02bfd2753c398454b408de843b0bf4f0b
5
5
  SHA512:
6
- metadata.gz: 66e97190536b1dd87c7b3396a9d3c93e23da823530965565e399266d2a9f8680c358f1b00ec7ed19a8da1687902d2403ac4ef46c96e5119fb50f563368a2b19e
7
- data.tar.gz: 50eb55d2c9df67fd68c8c2fb0e6b6271a96b32cda1dedac10a09fd6e0e6f3e61704594f3e46b125f1076640786d5f9225088e7af5190fac436caa9034dca4ac1
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/initializers/seory.rb`
24
+ Specify SEO content as ruby code. For example, `config/seory/*.rb`
25
25
 
26
26
  ```ruby
27
- # Specify SEO content based on `controller#action` rule
28
- match *%w[products#popular products#new_release] do
29
- title 'Great products | My Great Site[MGS]'
30
- meta_description 'A lot of great products'
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
- meta_keywords %w[Software Internet Service].join(',')
34
+ meta_keywords %w[Software Internet Service].join(',')
33
35
 
34
- h1 'Most popular products'
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
- # Match with request fullpath
43
- match path('/products/special-product') do
44
- title 'Special Product Detail'
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
- # Custom lookup rule with controller
48
- match(->(controller) { controller.params[:page].to_i == 1 }) do
49
- meta_keywords do
50
- search = assigns(:search_object)
43
+ title { product.name }
44
+ end
51
45
 
52
- # do something
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
- # Use custom word part
57
- match slug('products#index') do
58
- misc(:page_name) { "#{controller.params[:page].to_i} page | Good products") }
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
- title :page_name
61
- h1 :page_name
56
+ # do something
57
+ end
58
+ end
62
59
 
63
- meta_description { "Page for #{page_name}" }
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
- default do
67
- title 'My Great Service'
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
- Then we can use seory in your application.[TODO]
73
- ```ruby
74
- module ApplicationHelper
67
+ meta_description { "Page for #{misc(:page_name)}" }
68
+ }
69
+ end
70
+ end
75
71
 
76
- # provides seory() method,
77
- # which returns Seory::Runtime object with configured
78
- include Seory::Helper
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
@@ -1,7 +1,7 @@
1
1
  module Seory
2
2
  module RailsHelper
3
3
  def seory(repository = Seory.default_repository)
4
- repository.lookup(controller)
4
+ repository.lookup(self)
5
5
  end
6
6
  end
7
7
  end
@@ -24,10 +24,10 @@ module Seory
24
24
  clear_page_order_pre_calculation!
25
25
  end
26
26
 
27
- def lookup(controller)
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, controller, default).tap do |runtime|
30
+ Seory::Runtime.new(page, view_context, default).tap do |runtime|
31
31
  runtime.extend helper if helper
32
32
  end
33
33
  end
@@ -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, :controller
8
+ attr_reader :page_contents
8
9
 
9
- def initialize(page_contents, controller, fallback = nil)
10
+ def initialize(page_contents, view_context, fallback = nil)
10
11
  @page_contents = page_contents
11
- @controller = controller
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
- @controller.view_assigns[name.to_s]
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
@@ -1,3 +1,3 @@
1
1
  module Seory
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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) do
31
- Seory::ViewContextDouble.new(controller_double('products#index'))
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
- controller = controller_double('products/reviews#index') do
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(controller_double(*args)).title
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(controller_double('hi#index'))
98
+ repository.lookup(view_context_double('hi#index'))
99
99
  }.to raise_error(Seory::DuplicateDefault)
100
100
  end
101
101
  end
@@ -4,7 +4,8 @@ require 'seory/page'
4
4
 
5
5
  describe Seory::Runtime do
6
6
  let(:seory) do
7
- Seory::Runtime.new(page_contents, controller)
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
@@ -3,5 +3,9 @@ module Seory
3
3
  def controller_double(*args, &block)
4
4
  Seory::ControllerDouble.new(*args, &block)
5
5
  end
6
+
7
+ def view_context_double(*args, &block)
8
+ Seory::ViewContextDouble.new(controller_double(*args, &block))
9
+ end
6
10
  end
7
11
  end
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.1.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-20 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport