showcase 0.2.0.beta.3 → 0.2.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +2 -2
- data/Appraisals +4 -4
- data/gemfiles/{activerecord4.gemfile → rails_32.gemfile} +1 -1
- data/gemfiles/{activerecord3.gemfile → rails_4.gemfile} +1 -1
- data/lib/showcase/helpers/module_method_builder.rb +19 -0
- data/lib/showcase/helpers/present.rb +35 -0
- data/lib/showcase/helpers/seo_meta_builder.rb +1 -1
- data/lib/showcase/presenter.rb +11 -13
- data/lib/showcase/railtie.rb +1 -1
- data/lib/showcase/traits/base.rb +2 -16
- data/lib/showcase/traits/link_to.rb +3 -3
- data/lib/showcase/traits/seo.rb +9 -2
- data/lib/showcase/traits/share.rb +3 -1
- data/lib/showcase/version.rb +1 -1
- data/showcase.gemspec +1 -1
- data/spec/fixtures.rb +1 -1
- data/spec/traits/base_spec.rb +5 -5
- data/spec/traits/seo_spec.rb +19 -6
- data/spec/traits/share_spec.rb +2 -1
- metadata +7 -6
- data/lib/showcase/helpers.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a552e964feb8dee0c01780000c3b5fcff2dd69e4
|
4
|
+
data.tar.gz: 33e71c49318a0edb2874caa823a6d2bbd04b9373
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 911610134d24f4f00bd3315a634e5bec6b4a304e0a56035d7f1adf5e4cc0cc1075b24c9f3cd3cf75377975e619e1f53f2625aeb483839b2a15487b9d9009b662
|
7
|
+
data.tar.gz: 508533360df64c06a1de58e999abe82de44ada2c45207f27b015a37fae37507ecb45a33e52899a7c79549e72086697bce0953b4f92f21ae19563cc728ce7b665
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Showcase
|
2
|
+
module Helpers
|
3
|
+
module ModuleMethodBuilder
|
4
|
+
def define_module_method(name_chunks, &block)
|
5
|
+
method_name = Array(name_chunks).map(&:to_s).map(&:presence).compact.join("_")
|
6
|
+
if method_defined?(method_name)
|
7
|
+
false
|
8
|
+
else
|
9
|
+
method_module = Module.new do
|
10
|
+
define_method(method_name, &block)
|
11
|
+
end
|
12
|
+
include(method_module)
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'active_support/core_ext/hash/keys'
|
4
|
+
|
5
|
+
module Showcase
|
6
|
+
module Helpers
|
7
|
+
module Present
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
def presenter_context
|
11
|
+
if respond_to? :view_context
|
12
|
+
view_context
|
13
|
+
else
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def present(obj, klass = nil, context = presenter_context, options = {})
|
19
|
+
options.assert_valid_keys(:nil_presenter)
|
20
|
+
|
21
|
+
if obj || options.fetch(:nil_presenter, false)
|
22
|
+
klass ||= "#{obj.class.name}Presenter".constantize
|
23
|
+
klass.new(obj, context)
|
24
|
+
else
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def present_collection(obj, klass = nil, context = presenter_context, options = {})
|
30
|
+
obj.map { |o| present(o, klass, context, options) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/lib/showcase/presenter.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'delegate'
|
2
|
-
require 'showcase/helpers'
|
2
|
+
require 'showcase/helpers/present'
|
3
|
+
require 'showcase/helpers/module_method_builder'
|
3
4
|
require 'active_support/core_ext/array/extract_options'
|
4
5
|
require 'active_support/core_ext/hash/keys'
|
5
6
|
|
6
7
|
module Showcase
|
7
8
|
class Presenter < SimpleDelegator
|
8
|
-
include Helpers
|
9
|
+
include Helpers::Present
|
10
|
+
extend Helpers::ModuleMethodBuilder
|
9
11
|
|
10
12
|
attr_reader :view_context
|
11
13
|
|
@@ -47,19 +49,15 @@ module Showcase
|
|
47
49
|
options.assert_valid_keys(:with, :nil_presenter)
|
48
50
|
presenter_klass = options.fetch(:with, nil)
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
options.slice(:nil_presenter))
|
58
|
-
end
|
52
|
+
args.each do |attr|
|
53
|
+
define_module_method attr do
|
54
|
+
send(method,
|
55
|
+
object.send(attr),
|
56
|
+
presenter_klass,
|
57
|
+
view_context,
|
58
|
+
options.slice(:nil_presenter))
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
62
|
-
include(methods_module)
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
data/lib/showcase/railtie.rb
CHANGED
@@ -4,7 +4,7 @@ module Showcase
|
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
initializer "action_view.initialize_showcase" do
|
6
6
|
ActiveSupport.on_load(:action_view) do
|
7
|
-
ActionView::Base.send :include, Showcase::Helpers
|
7
|
+
ActionView::Base.send :include, Showcase::Helpers::Present
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/lib/showcase/traits/base.rb
CHANGED
@@ -3,23 +3,9 @@ module Showcase
|
|
3
3
|
module Base
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def define_method?(name_chunks, &block)
|
10
|
-
method_name = Array(name_chunks).map(&:to_s).map(&:presence).compact.join("_")
|
11
|
-
if method_defined?(method_name)
|
12
|
-
false
|
13
|
-
else
|
14
|
-
method_module = Module.new do
|
15
|
-
define_method(method_name, &block)
|
16
|
-
end
|
17
|
-
include(method_module)
|
18
|
-
true
|
19
|
-
end
|
20
|
-
end
|
6
|
+
included do
|
7
|
+
extend Helpers::ModuleMethodBuilder
|
21
8
|
end
|
22
|
-
|
23
9
|
end
|
24
10
|
end
|
25
11
|
end
|
@@ -10,15 +10,15 @@ module Showcase
|
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def link_to(name = nil, &block)
|
13
|
-
|
13
|
+
define_module_method [name, :url] do
|
14
14
|
Helpers::ConfigObject.new(self, &block).to_struct.url
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
define_module_method [name, :link_active?] do
|
18
18
|
Helpers::ConfigObject.new(self, &block).to_struct.active
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
define_module_method [name, :link] do |*args, &link_block|
|
22
22
|
config = Helpers::ConfigObject.new(self, &block).to_struct
|
23
23
|
|
24
24
|
html_options = HtmlOptions.new(config.html_options)
|
data/lib/showcase/traits/seo.rb
CHANGED
@@ -9,9 +9,16 @@ module Showcase
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
|
12
|
+
def default_seo_options(&block)
|
13
|
+
define_module_method :default_seo_options do
|
14
|
+
Helpers::ConfigObject.new(self, &block).to_hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
def seo(name = nil, options = {}, &block)
|
13
|
-
|
14
|
-
meta =
|
19
|
+
define_module_method [name, :seo_tags] do |options = {}|
|
20
|
+
meta = respond_to?(:default_seo_options) ? default_seo_options : {}
|
21
|
+
meta.merge!(Helpers::ConfigObject.new(self, &block).to_hash)
|
15
22
|
meta.merge!(options.symbolize_keys) if options
|
16
23
|
|
17
24
|
builder = Helpers::SeoMetaBuilder.new(view_context)
|
@@ -45,9 +45,11 @@ module Showcase
|
|
45
45
|
html_options = meta.html_options || {}
|
46
46
|
params = Hash[
|
47
47
|
settings[:params].map do |param, meta_key|
|
48
|
-
[
|
48
|
+
values = [:"#{social}_#{meta_key}", meta_key].map { |key| meta[key] }
|
49
|
+
[ param, values.find(&:presence) ]
|
49
50
|
end
|
50
51
|
]
|
52
|
+
|
51
53
|
c.url "#{settings[:url]}?#{params.to_query}"
|
52
54
|
c.label settings[:label]
|
53
55
|
c.html_options = html_options.reverse_merge(target: '_blank')
|
data/lib/showcase/version.rb
CHANGED
data/showcase.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = 'showcase'
|
8
8
|
gem.version = Showcase::VERSION
|
9
9
|
gem.authors = ['Stefano Verna']
|
10
|
-
gem.email = ['stefano.verna@
|
10
|
+
gem.email = ['stefano.verna@gmail.com']
|
11
11
|
gem.description = %q{A barebone and framework agnostic presenter implementation}
|
12
12
|
gem.summary = %q{A barebone and framework agnostic presenter implementation}
|
13
13
|
gem.homepage = 'https://github.com/welaika/showcase'
|
data/spec/fixtures.rb
CHANGED
data/spec/traits/base_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Showcase::Traits
|
4
4
|
describe Base do
|
5
|
-
describe '.
|
5
|
+
describe '.define_module_method' do
|
6
6
|
|
7
7
|
it 'defines an instance method' do
|
8
8
|
klass = Class.new do
|
9
9
|
include Base
|
10
|
-
|
10
|
+
define_module_method :foo do
|
11
11
|
true
|
12
12
|
end
|
13
13
|
end
|
@@ -19,7 +19,7 @@ module Showcase::Traits
|
|
19
19
|
klass = Class.new do
|
20
20
|
include Base
|
21
21
|
|
22
|
-
|
22
|
+
define_module_method :foo do
|
23
23
|
true
|
24
24
|
end
|
25
25
|
|
@@ -46,7 +46,7 @@ module Showcase::Traits
|
|
46
46
|
it 'joins them in snake case' do
|
47
47
|
klass = Class.new do
|
48
48
|
include Base
|
49
|
-
|
49
|
+
define_module_method [:foo, :bar] do
|
50
50
|
true
|
51
51
|
end
|
52
52
|
end
|
@@ -57,7 +57,7 @@ module Showcase::Traits
|
|
57
57
|
it 'ignores blank chunks' do
|
58
58
|
klass = Class.new do
|
59
59
|
include Base
|
60
|
-
|
60
|
+
define_module_method ["", :bar] do
|
61
61
|
true
|
62
62
|
end
|
63
63
|
end
|
data/spec/traits/seo_spec.rb
CHANGED
@@ -12,25 +12,38 @@ module Showcase::Traits
|
|
12
12
|
Class.new(Showcase::Presenter) do
|
13
13
|
include Seo
|
14
14
|
|
15
|
+
default_seo_options do |c|
|
16
|
+
c.title_suffix = ' - qux'
|
17
|
+
end
|
18
|
+
|
15
19
|
seo do |c|
|
16
20
|
c.title = 'foo'
|
17
21
|
c.description 'bar'
|
18
|
-
c.title_suffix = ' - qux'
|
19
22
|
end
|
20
23
|
end
|
21
24
|
}
|
22
25
|
|
23
|
-
describe '
|
24
|
-
let(:
|
26
|
+
describe '.seo' do
|
27
|
+
let(:expected_options) { { title_suffix: ' - qux' } }
|
28
|
+
let(:expected_description) { 'bar' }
|
29
|
+
let(:expected_title) { 'foo' }
|
25
30
|
|
26
31
|
before do
|
27
32
|
Showcase::Helpers::SeoMetaBuilder.stub(:new).with(view).and_return(builder)
|
28
|
-
builder.stub(:title).with(
|
29
|
-
builder.stub(:description).with(
|
33
|
+
builder.stub(:title).with(expected_title, expected_options).and_return('<title>')
|
34
|
+
builder.stub(:description).with(expected_description, expected_options).and_return('<description>')
|
30
35
|
end
|
31
36
|
|
32
37
|
it 'defines a seo_tags method that ouputs seo meta tags' do
|
33
|
-
expect(subject.seo_tags
|
38
|
+
expect(subject.seo_tags).to eq '<title><description>'
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#seo_tags' do
|
42
|
+
let(:expected_title) { 'other' }
|
43
|
+
|
44
|
+
it 'allows to override options' do
|
45
|
+
expect(subject.seo_tags(title: 'other')).to eq '<title><description>'
|
46
|
+
end
|
34
47
|
end
|
35
48
|
end
|
36
49
|
|
data/spec/traits/share_spec.rb
CHANGED
@@ -14,6 +14,7 @@ module Showcase::Traits
|
|
14
14
|
share do |c|
|
15
15
|
c.url = 'url'
|
16
16
|
c.text = 'text'
|
17
|
+
c.twitter_text = 'twitter text'
|
17
18
|
c.image_url = 'image'
|
18
19
|
c.html_options = { role: 'share' }
|
19
20
|
end
|
@@ -29,7 +30,7 @@ module Showcase::Traits
|
|
29
30
|
|
30
31
|
describe '#social_share' do
|
31
32
|
expected_urls = {
|
32
|
-
twitter: "https://twitter.com/intent/tweet?text=text&url=url",
|
33
|
+
twitter: "https://twitter.com/intent/tweet?text=twitter+text&url=url",
|
33
34
|
facebook: "http://www.facebook.com/sharer/sharer.php?u=url",
|
34
35
|
gplus: "https://plus.google.com/share?url=url",
|
35
36
|
pinterest: "http://www.pinterest.com/pin/create/button/?media=image&title=text&url=url",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: showcase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.beta.
|
4
|
+
version: 0.2.0.beta.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '0'
|
83
83
|
description: A barebone and framework agnostic presenter implementation
|
84
84
|
email:
|
85
|
-
- stefano.verna@
|
85
|
+
- stefano.verna@gmail.com
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
@@ -95,15 +95,16 @@ files:
|
|
95
95
|
- LICENSE.txt
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
-
- gemfiles/
|
99
|
-
- gemfiles/
|
98
|
+
- gemfiles/rails_32.gemfile
|
99
|
+
- gemfiles/rails_4.gemfile
|
100
100
|
- lib/generators/showcase/presenter/USAGE
|
101
101
|
- lib/generators/showcase/presenter/presenter_generator.rb
|
102
102
|
- lib/generators/showcase/presenter/templates/presenter.rb
|
103
103
|
- lib/showcase.rb
|
104
|
-
- lib/showcase/helpers.rb
|
105
104
|
- lib/showcase/helpers/config_object.rb
|
106
105
|
- lib/showcase/helpers/html_options.rb
|
106
|
+
- lib/showcase/helpers/module_method_builder.rb
|
107
|
+
- lib/showcase/helpers/present.rb
|
107
108
|
- lib/showcase/helpers/seo_meta_builder.rb
|
108
109
|
- lib/showcase/presenter.rb
|
109
110
|
- lib/showcase/railtie.rb
|
data/lib/showcase/helpers.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'active_support/inflector'
|
3
|
-
require 'active_support/core_ext/hash/keys'
|
4
|
-
|
5
|
-
module Showcase
|
6
|
-
module Helpers
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
def presenter_context
|
10
|
-
if respond_to? :view_context
|
11
|
-
view_context
|
12
|
-
else
|
13
|
-
self
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def present(obj, klass = nil, context = presenter_context, options = {})
|
18
|
-
options.assert_valid_keys(:nil_presenter)
|
19
|
-
|
20
|
-
if obj || options.fetch(:nil_presenter, false)
|
21
|
-
klass ||= "#{obj.class.name}Presenter".constantize
|
22
|
-
klass.new(obj, context)
|
23
|
-
else
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def present_collection(obj, klass = nil, context = presenter_context, options = {})
|
29
|
-
obj.map { |o| present(o, klass, context, options) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|