seory 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 596af9785f1ff0011c40d7816efbe7ab4bfbdc4e
4
+ data.tar.gz: e7f043fea0dcebf5175e085e74c7d5340435bda2
5
+ SHA512:
6
+ metadata.gz: 96abaeb3e7afed6dd3efa2f4e8686ddffc3e6d3e2f2e7c7db348b53d063cb8882eed21ed0c0e0c414cedb936077e16a2021629501ebcecdb15174bc4f0b0c434
7
+ data.tar.gz: a9e4f15b2ab04800148b5378b7e88476e8241b0829e003407f1de4b705aef185ecb4c80c8b9d324e0562d639b4acdcb7f5667778f395beda378b2ade400412c0
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seory.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 moro
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,87 @@
1
+ # Seory
2
+
3
+ Manage SEO contets in Rails app. based on controller, action and more complex context.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'seory'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install seory
18
+
19
+ ## Usage
20
+
21
+ Specify SEO content as ruby code. For example, `config/initializers/seory.rb`
22
+
23
+ ```ruby
24
+ # Specify SEO content based on `controller#action` rule
25
+ match %w[products#popular products#new_release], {
26
+ title: 'Great products | My Great Site[MGS]'
27
+ desc: 'A lot of greate products'
28
+
29
+ keywords: %w[Software Internet Service]
30
+
31
+ h1: 'Most popular products'
32
+ }
33
+
34
+ # Can contain dynamic content based on controller using assigned ivar
35
+ match 'brands#show' {
36
+ title: -> { assign(:brand).name }
37
+ }
38
+
39
+ # Custom lookup rule with controller
40
+ match ->(controller) { controller.params[:page].to_i == 1 }, {
41
+ keywords: -> do
42
+ search = assign(:search_object)
43
+
44
+ end
45
+ }
46
+
47
+ # [TODO] Use custom word part
48
+ match %w[products#index] do
49
+ page_name { "#{page_part} Good products") }
50
+
51
+ title :page_name
52
+ h1 :page_name
53
+
54
+ desc { "Page for #{page_name}" }
55
+ }
56
+
57
+ default do
58
+ title 'My Great Service'
59
+ h1 { I18n.t("#{controller_name}.h1", scope: 'label.misc_pages' }
60
+ end
61
+ ```
62
+
63
+ Then we can use seory in your application.
64
+ ```ruby
65
+ module ApplicationHelper
66
+
67
+ # provides seory() method,
68
+ # which returns Seory::Runtime object with configured
69
+ include Seory::Helper
70
+ end
71
+
72
+ ```haml
73
+ %html
74
+ %head
75
+ %title= seory.title
76
+ ...
77
+ %body
78
+ %h1= seory.h1
79
+ ```
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it ( https://github.com/esminc/seory/fork )
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/seory/dsl.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'seory/page_contents'
2
+ require 'seory/runtime'
3
+
4
+ module Seory
5
+ module Dsl
6
+ extend self
7
+
8
+ def describe(&block)
9
+ [].tap do |repositories|
10
+ Descriptor.new(repositories).instance_exec(&block)
11
+ end
12
+ end
13
+
14
+ def lookup(controller)
15
+ page_contents = repositories.detect {|page| page.match?(controller) }
16
+ Seory::Runtime.new(page_contents, controller)
17
+ end
18
+
19
+ class PageContentsBuilder
20
+ def initialize(*conditions)
21
+ @page_contents = PageContents.new(*conditions)
22
+ end
23
+
24
+ def build!(&block)
25
+ instance_exec(&block)
26
+
27
+ @page_contents
28
+ end
29
+
30
+ Seory::Runtime::CONTENTS.each do |name|
31
+ define_method(name) do |val = nil, &block|
32
+ @page_contents.define(name, val, &block)
33
+ end
34
+ end
35
+ end
36
+
37
+ class Descriptor
38
+ def initialize(repositories)
39
+ @repositories = repositories
40
+ end
41
+
42
+ def match(*conditions, &def_builder)
43
+ @repositories << PageContentsBuilder.new(*conditions).build!(&def_builder)
44
+ end
45
+
46
+ def default(&def_builder)
47
+ match(:default, &def_builder)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ require 'seory'
2
+ require 'active_support/all'
3
+
4
+ module Seory
5
+ class EmptyCondition < ::Seory::Error; end
6
+
7
+ class PageContents
8
+ def initialize(*conditions, &block)
9
+ @conditions = block_given? ? block : conditions
10
+ raise EmptyCondition if @conditions.blank?
11
+
12
+ @contents = {}
13
+ end
14
+
15
+ def define(name, value = nil, &block)
16
+ @contents[name] = block_given? ? block : value
17
+ end
18
+
19
+ def content_for(name)
20
+ @contents[name]
21
+ end
22
+
23
+ def match?(controller)
24
+ return true if @conditions == [:default]
25
+
26
+ if @conditions.respond_to?(:call)
27
+ @conditions.call(controller)
28
+ else
29
+ @conditions.include?(action_slug(controller))
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def action_slug(controller)
36
+ [controller.controller_name, controller.action_name].join('#')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ # TODO move somewhere
2
+ require 'active_support/all'
3
+
4
+ module Seory
5
+ class Runtime
6
+ delegate :action_name, to: :controller
7
+
8
+ CONTENTS = %w[title h1 h2 meta_description meta_keywords canonical_url image_url].map(&:to_sym)
9
+
10
+ attr_reader :controller
11
+
12
+ def initialize(page_contents, controller)
13
+ @page_contents = page_contents
14
+ @controller = controller
15
+ end
16
+
17
+ CONTENTS.each do |name|
18
+ define_method(name) { calculate_content_for(name) }
19
+ end
20
+
21
+ private
22
+
23
+ def calculate_content_for(name)
24
+ case page_content = @page_contents.content_for(name)
25
+ when String
26
+ page_content
27
+ when ->(o) { o.respond_to?(:call) }
28
+ instance_exec(&page_content)
29
+ else
30
+ raise 'BUG'
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Seory
2
+ VERSION = "0.0.1"
3
+ end
data/lib/seory.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "seory/version"
2
+
3
+ module Seory
4
+ class Error < RuntimeError
5
+ end
6
+ end
data/seory.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'seory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "seory"
8
+ spec.version = Seory::VERSION
9
+ spec.authors = ["moro"]
10
+ spec.email = ["moronatural@gmail.com"]
11
+ spec.summary = %q{SEO contents manager for Rails.}
12
+ spec.description = %q{Manage SEO contets in Rails app. based on controller, action and more complex context.}
13
+ spec.homepage = ""
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 "activesupport", "> 3.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'seory/dsl'
3
+
4
+ describe Seory::Dsl do
5
+ before do
6
+ Seory::Dsl.describe do
7
+ match 'products#index' do
8
+ title 'My Great Product'
9
+ h1 'Great Product Name'
10
+ end
11
+
12
+ default do
13
+ title 'Misc site'
14
+ h1 { controller.controller_name.upcase }
15
+ end
16
+ end
17
+ end
18
+
19
+ subject(:seory) { Seory::Dsl.lookup(controller) }
20
+
21
+ context 'at products#index' do
22
+ let(:controller) { double('controller', controller_name: 'products', action_name: 'index') }
23
+
24
+ specify { expect(seory.title).to eq 'My Great Product' }
25
+ specify { expect(seory.h1).to eq 'Great Product Name' }
26
+ end
27
+
28
+ context 'at misc#show' do
29
+ let(:controller) { double('controller', controller_name: 'misc', action_name: 'show') }
30
+
31
+ specify { expect(seory.h1).to eq 'MISC' }
32
+ end
33
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'seory/page_contents'
3
+
4
+ describe Seory::PageContents do
5
+ specify 'cant define without condition' do
6
+ expect { Seory::PageContents.new }.to raise_error(Seory::EmptyCondition)
7
+ end
8
+
9
+ context 'content PageContents' do
10
+ let(:seory_def) do
11
+ Seory::PageContents.new(:default)
12
+ end
13
+
14
+ context 'define static content' do
15
+ before do
16
+ seory_def.define(:title, 'A title')
17
+ end
18
+
19
+ specify { expect(seory_def.content_for(:title)).to eq 'A title' }
20
+ end
21
+
22
+ context 'define dynamic content' do
23
+ before do
24
+ seory_def.define(:title) { 'A title' }
25
+ end
26
+
27
+ specify { expect(seory_def.content_for(:title).call).to eq 'A title' }
28
+ end
29
+ end
30
+
31
+ describe 'condition and #match?' do
32
+ def init_with(*args, &block)
33
+ Seory::PageContents.new(*args, &block)
34
+ end
35
+
36
+ let(:controller) { double('controller', controller_name: 'people', action_name: 'index') }
37
+
38
+ specify '`:default` matches everything (stacked in bottom)' do
39
+ expect(init_with(:default)).to be_match(double('something'))
40
+ end
41
+
42
+ describe 'controller_name#action_name' do
43
+ specify do
44
+ expect(init_with('people#index').match?(controller)).to be_truthy
45
+ end
46
+
47
+ specify do
48
+ expect(init_with('people#show').match?(controller)).to be_falsy
49
+ end
50
+
51
+ specify 'supports some actions' do
52
+ expect(init_with('people#show', 'people#index').match?(controller)).to be_truthy
53
+ end
54
+
55
+ specify do
56
+ page_contents = init_with {|c| c.controller_name == 'people' }
57
+
58
+ expect(page_contents.match?(controller)).to be_truthy
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'seory/runtime'
3
+ require 'seory/page_contents'
4
+
5
+ describe Seory::Runtime do
6
+ let(:seory) do
7
+ Seory::Runtime.new(page_contents, controller)
8
+ end
9
+
10
+ let(:controller) { double('controller') }
11
+ let(:page_contents) { Seory::PageContents.new(:default) }
12
+
13
+ context 'static content' do
14
+ before do
15
+ page_contents.define(:title, 'A title')
16
+ page_contents.define(:h1, 'Most importatnt HEADER 1')
17
+ end
18
+
19
+ describe '#title' do
20
+ specify { expect(seory.title).to eq 'A title' }
21
+ end
22
+
23
+ describe '#h1' do
24
+ specify { expect(seory.h1).to eq 'Most importatnt HEADER 1' }
25
+ end
26
+ end
27
+
28
+ context 'controller based dynamic content' do
29
+ before do
30
+ allow(controller).to receive(:action_name) { 'edit' }
31
+
32
+ page_contents.define(:title) { "#{action_name.upcase} | My Site" }
33
+ end
34
+
35
+ describe '#titie' do
36
+ specify { expect(seory.title).to eq 'EDIT | My Site' }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,82 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # (such as loading up an entire rails app) will add to the boot time of your
9
+ # test suite on EVERY test run, even for an individual file that may not need
10
+ # all of that loaded.
11
+ #
12
+ # The `.rspec` file also contains a few flags that are not defaults but that
13
+ # users commonly want.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # The settings below are suggested to provide a good initial experience
18
+ # with RSpec, but feel free to customize to your heart's content.
19
+ =begin
20
+ # These two settings work together to allow you to limit a spec run
21
+ # to individual examples or groups you care about by tagging them with
22
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
23
+ # get run.
24
+ config.filter_run :focus
25
+ config.run_all_when_everything_filtered = true
26
+
27
+ # Many RSpec users commonly either run the entire suite or an individual
28
+ # file, and it's useful to allow more verbose output when running an
29
+ # individual spec file.
30
+ if config.files_to_run.one?
31
+ # RSpec filters the backtrace by default so as not to be so noisy.
32
+ # This causes the full backtrace to be printed when running a single
33
+ # spec file (e.g. to troubleshoot a particular spec failure).
34
+ config.full_backtrace = true
35
+
36
+ # Use the documentation formatter for detailed output,
37
+ # unless a formatter has already been configured
38
+ # (e.g. via a command-line flag).
39
+ config.formatter = 'doc' if config.formatters.none?
40
+ end
41
+
42
+ # Print the 10 slowest examples and example groups at the
43
+ # end of the spec run, to help surface which specs are running
44
+ # particularly slow.
45
+ config.profile_examples = 10
46
+
47
+ # Run specs in random order to surface order dependencies. If you find an
48
+ # order dependency and want to debug it, you can fix the order by providing
49
+ # the seed, which is printed after each run.
50
+ # --seed 1234
51
+ config.order = :random
52
+
53
+ # Seed global randomization in this process using the `--seed` CLI option.
54
+ # Setting this allows you to use `--seed` to deterministically reproduce
55
+ # test failures related to randomization by passing the same `--seed` value
56
+ # as the one that triggered the failure.
57
+ Kernel.srand config.seed
58
+
59
+ # rspec-expectations config goes here. You can use an alternate
60
+ # assertion/expectation library such as wrong or the stdlib/minitest
61
+ # assertions if you prefer.
62
+ config.expect_with :rspec do |expectations|
63
+ # Enable only the newer, non-monkey-patching expect syntax.
64
+ # For more details, see:
65
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
66
+ expectations.syntax = :expect
67
+ end
68
+
69
+ # rspec-mocks config goes here. You can use an alternate test double
70
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
71
+ config.mock_with :rspec do |mocks|
72
+ # Enable only the newer, non-monkey-patching expect syntax.
73
+ # For more details, see:
74
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
75
+ mocks.syntax = :expect
76
+
77
+ # Prevents you from mocking or stubbing a method that does not exist on
78
+ # a real object. This is generally recommended.
79
+ mocks.verify_partial_doubles = true
80
+ end
81
+ =end
82
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - moro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Manage SEO contets in Rails app. based on controller, action and more
56
+ complex context.
57
+ email:
58
+ - moronatural@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/seory.rb
70
+ - lib/seory/dsl.rb
71
+ - lib/seory/page_contents.rb
72
+ - lib/seory/runtime.rb
73
+ - lib/seory/version.rb
74
+ - seory.gemspec
75
+ - spec/seory/dsl_spec.rb
76
+ - spec/seory/page_contents_spec.rb
77
+ - spec/seory/runtime_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: SEO contents manager for Rails.
103
+ test_files:
104
+ - spec/seory/dsl_spec.rb
105
+ - spec/seory/page_contents_spec.rb
106
+ - spec/seory/runtime_spec.rb
107
+ - spec/spec_helper.rb