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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d6a631420d19d2a548cdf36d56577c48ae24930
4
- data.tar.gz: bd24f9fc93109defc060e10b88d2dc2c57980a6a
3
+ metadata.gz: a552e964feb8dee0c01780000c3b5fcff2dd69e4
4
+ data.tar.gz: 33e71c49318a0edb2874caa823a6d2bbd04b9373
5
5
  SHA512:
6
- metadata.gz: df878541e87c19106087fa2f1a8eb7610fca82637b6e7ed13e056a98284fafbb55ec428e9922c0b16d9e9404b8e95a8c543595f0ba9a179472376b76a6a3a4dc
7
- data.tar.gz: 2075e6deb475f90d8f4f215478e2b027af35def0f9abb5fc10a4e2f26d068a78957457009a3f4d7877331517a9cdf5a121064d37270c75455b9119a5d4fad82c
6
+ metadata.gz: 911610134d24f4f00bd3315a634e5bec6b4a304e0a56035d7f1adf5e4cc0cc1075b24c9f3cd3cf75377975e619e1f53f2625aeb483839b2a15487b9d9009b662
7
+ data.tar.gz: 508533360df64c06a1de58e999abe82de44ada2c45207f27b015a37fae37507ecb45a33e52899a7c79549e72086697bce0953b4f92f21ae19563cc728ce7b665
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ gemfiles/*.gemfile.lock
19
+
data/.travis.yml CHANGED
@@ -5,8 +5,8 @@ rvm:
5
5
  - "2.0.0"
6
6
 
7
7
  gemfile:
8
- - "gemfiles/activerecord3.gemfile"
9
- - "gemfiles/activerecord4.gemfile"
8
+ - "gemfiles/rails_32.gemfile"
9
+ - "gemfiles/rails_4.gemfile"
10
10
 
11
11
  script: "bundle exec rake spec"
12
12
 
data/Appraisals CHANGED
@@ -1,8 +1,8 @@
1
- appraise "activerecord3" do
2
- gem "activerecord", "3.2.14"
1
+ appraise "rails-32" do
2
+ gem "rails", "3.2.14"
3
3
  end
4
4
 
5
- appraise "activerecord4" do
6
- gem "activerecord", "4.0.0"
5
+ appraise "rails-4" do
6
+ gem "rails", "4.0.0"
7
7
  end
8
8
 
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "activerecord", "4.0.0"
6
+ gem "rails", "3.2.14"
7
7
 
8
8
  gemspec :path=>"../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "activerecord", "3.2.14"
6
+ gem "rails", "4.0.0"
7
7
 
8
8
  gemspec :path=>"../"
@@ -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
+
@@ -31,7 +31,7 @@ module Showcase
31
31
  private
32
32
 
33
33
  def first_nonblank(values)
34
- Array(values).map(&:presence).compact.first
34
+ Array(values).find(&:presence)
35
35
  end
36
36
 
37
37
  def seo_meta_tags(*args)
@@ -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
- methods_module = Module.new do
51
- args.each do |attr|
52
- define_method attr do
53
- send(method,
54
- object.send(attr),
55
- presenter_klass,
56
- view_context,
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
@@ -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
@@ -3,23 +3,9 @@ module Showcase
3
3
  module Base
4
4
  extend ActiveSupport::Concern
5
5
 
6
- module ClassMethods
7
- private
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
- define_method? [name, :url] do
13
+ define_module_method [name, :url] do
14
14
  Helpers::ConfigObject.new(self, &block).to_struct.url
15
15
  end
16
16
 
17
- define_method? [name, :link_active?] do
17
+ define_module_method [name, :link_active?] do
18
18
  Helpers::ConfigObject.new(self, &block).to_struct.active
19
19
  end
20
20
 
21
- define_method? [name, :link] do |*args, &link_block|
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)
@@ -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
- define_method? [name, :seo_tags] do |options = {}|
14
- meta = Helpers::ConfigObject.new(self, &block).to_hash
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
- [ param, meta.send(meta_key) ]
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')
@@ -1,4 +1,4 @@
1
1
  module Showcase
2
- VERSION = "0.2.0.beta.3"
2
+ VERSION = "0.2.0.beta.4"
3
3
  end
4
4
 
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@welaika.com']
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
@@ -87,7 +87,7 @@ class NilClassPresenter < Showcase::Presenter
87
87
  end
88
88
 
89
89
  class Context
90
- include Showcase::Helpers
90
+ include Showcase::Helpers::Present
91
91
 
92
92
  def bold(text)
93
93
  "**#{text}**"
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  module Showcase::Traits
4
4
  describe Base do
5
- describe '.define_method?' do
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
- define_method? :foo do
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
- define_method? :foo do
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
- define_method? [:foo, :bar] do
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
- define_method? ["", :bar] do
60
+ define_module_method ["", :bar] do
61
61
  true
62
62
  end
63
63
  end
@@ -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 '#seo' do
24
- let(:options) { { title_suffix: ' - qux' } }
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('foo', options).and_return('<title>')
29
- builder.stub(:description).with('bar', options).and_return('<description>')
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(options)).to eq '<title><description>'
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
 
@@ -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.3
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-10-30 00:00:00.000000000 Z
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@welaika.com
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/activerecord3.gemfile
99
- - gemfiles/activerecord4.gemfile
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
@@ -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
-