showcase 0.2.0.beta.5 → 0.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/.travis.yml +1 -7
- data/Gemfile +0 -3
- data/README.md +20 -40
- data/Rakefile +1 -14
- data/lib/showcase/helpers/seo_meta_builder.rb +7 -27
- data/lib/showcase/helpers.rb +33 -0
- data/lib/showcase/presenter.rb +13 -12
- data/lib/showcase/railtie.rb +1 -1
- data/lib/showcase/traits/base.rb +13 -2
- data/lib/showcase/traits/link_to.rb +14 -8
- data/lib/showcase/traits/record.rb +11 -35
- data/lib/showcase/traits/seo.rb +4 -18
- data/lib/showcase/traits/share.rb +2 -6
- data/lib/showcase/version.rb +1 -1
- data/showcase.gemspec +1 -1
- data/spec/fixtures.rb +1 -1
- data/spec/helpers/seo_meta_builder_spec.rb +8 -41
- data/spec/traits/base_spec.rb +4 -20
- data/spec/traits/link_to_spec.rb +3 -16
- data/spec/traits/record_spec.rb +0 -9
- data/spec/traits/seo_spec.rb +5 -20
- data/spec/traits/share_spec.rb +1 -12
- metadata +4 -9
- data/Appraisals +0 -8
- data/gemfiles/rails_32.gemfile +0 -8
- data/gemfiles/rails_4.gemfile +0 -8
- data/lib/showcase/helpers/html_options.rb +0 -22
- data/lib/showcase/helpers/module_method_builder.rb +0 -19
- data/lib/showcase/helpers/present.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72574756357dcfeea3882c9cc85310c932bc272d
|
4
|
+
data.tar.gz: 98f5d60b67e5dba3f0d870ae033b9dacc6ffad28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b49b695ea0301b22c47239c144ceaf4ccfa7a22c6ec1ab809f7660581792c196953060183064a7a9e2d61a230d2fbd7ceccc3ce9ce2289e617f6457e39d1b86
|
7
|
+
data.tar.gz: dcfd53204bc986fc2389707a130afe5d7395b110f34d30b63cd562375f12140a7f03474f07c2d88a987304da6bc9fac29d81875eec3dcc8e45c25ba624886a2a
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,42 +3,36 @@
|
|
3
3
|
A simple (< 100 lines of code) but powerful exhibit/presenter implementation.
|
4
4
|
It's framework agnostic: works with Rails, Padrino or just Sinatra.
|
5
5
|
|
6
|
-
Since version 0.2.0 Showcase is bundled with [a set of
|
6
|
+
Since version 0.2.0 Showcase is bundled with [a set of "traits"](https://github.com/stefanoverna/showcase#traits)
|
7
7
|
you can pick and choose to augment your presenters with additional sugar
|
8
|
-
(available in Rails
|
8
|
+
(available in Rails only).
|
9
9
|
|
10
|
-
## Why should I use
|
10
|
+
## Why should I use the Exhibit pattern in my Rails app?
|
11
11
|
|
12
|
-
See [Avdi's
|
12
|
+
See [Avdi's introductory post](http://devblog.avdi.org/2012/06/04/displaycase-gem-now-available/).
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
16
16
|
Add this line to your application's Gemfile:
|
17
17
|
|
18
|
-
|
19
|
-
gem 'showcase'
|
20
|
-
```
|
18
|
+
gem 'showcase'
|
21
19
|
|
22
20
|
And then execute:
|
23
21
|
|
24
|
-
|
25
|
-
$ bundle
|
26
|
-
```
|
22
|
+
$ bundle
|
27
23
|
|
28
24
|
Or install it yourself as:
|
29
25
|
|
30
|
-
|
31
|
-
$ gem install showcase
|
32
|
-
```
|
26
|
+
$ gem install showcase
|
33
27
|
|
34
28
|
## Usage
|
35
29
|
|
36
|
-
With Rails, you're already set, move on! With Padrino, include `Showcase::Helpers
|
30
|
+
With Rails, you're already set, move on! With Padrino, include `Showcase::Helpers`
|
37
31
|
in your app `helpers` block.
|
38
32
|
|
39
33
|
```ruby
|
40
34
|
helpers do
|
41
|
-
include Showcase::Helpers
|
35
|
+
include Showcase::Helpers
|
42
36
|
end
|
43
37
|
```
|
44
38
|
|
@@ -88,15 +82,16 @@ end
|
|
88
82
|
|
89
83
|
### Generators
|
90
84
|
|
91
|
-
Showcase comes with a generator to
|
85
|
+
Showcase comes with a generator to make the Presenter creation process a little
|
86
|
+
faster:
|
92
87
|
|
93
88
|
```
|
94
89
|
rails generate showcase:presenter User
|
95
90
|
```
|
96
91
|
|
97
|
-
Will generate `app/presenters/user_presenter.rb`. If your
|
92
|
+
Will generate `app/presenters/user_presenter.rb`. If your app has a file called
|
98
93
|
`app/presenters/base_presenter.rb`, the newly created presenter will inherit
|
99
|
-
|
94
|
+
form `BasePresenter` instead of `Shocase::Presenter`.
|
100
95
|
|
101
96
|
### Traits
|
102
97
|
|
@@ -132,7 +127,7 @@ Super useful in acceptance testing to check the presence of a record inside a
|
|
132
127
|
view:
|
133
128
|
|
134
129
|
```erb
|
135
|
-
<% present(@project
|
130
|
+
<% present(@project).box do %>
|
136
131
|
<p>Hi there!</p>
|
137
132
|
<% end %>
|
138
133
|
```
|
@@ -140,24 +135,11 @@ view:
|
|
140
135
|
Produces the following:
|
141
136
|
|
142
137
|
```html
|
143
|
-
<div class="project
|
138
|
+
<div class="project" id="project_12">
|
144
139
|
<p>Hi there</p>
|
145
140
|
</div>
|
146
141
|
```
|
147
142
|
|
148
|
-
Additional HTML attributes can be optionally specified within a config block
|
149
|
-
inside the presenter:
|
150
|
-
|
151
|
-
```ruby
|
152
|
-
class ProjectPresenter < Showcase::Presenter
|
153
|
-
include Showcase::Traits::Record
|
154
|
-
|
155
|
-
box do |c|
|
156
|
-
c.html_options class: 'another-class', role: 'project'
|
157
|
-
end
|
158
|
-
end
|
159
|
-
```
|
160
|
-
|
161
143
|
#### `Showcase::Traits::LinkTo`
|
162
144
|
|
163
145
|
Adds a nice DSL to declare links within your presenter.
|
@@ -167,16 +149,15 @@ class ProjectPresenter < Showcase::Presenter
|
|
167
149
|
include Showcase::Traits::LinkTo
|
168
150
|
|
169
151
|
link_to do |c|
|
170
|
-
c.url
|
171
|
-
c.label
|
172
|
-
c.active
|
173
|
-
c.active_class 'current'
|
174
|
-
c.html_options role: 'label'
|
152
|
+
c.url h.project_path(self)
|
153
|
+
c.label name
|
154
|
+
c.active h.controller_name == 'projects'
|
175
155
|
end
|
176
156
|
|
177
157
|
link_to :tasks do
|
178
158
|
c.url h.project_tasks_path(self)
|
179
159
|
c.label "Tasks"
|
160
|
+
c.active h.controller_name == 'tasks'
|
180
161
|
end
|
181
162
|
end
|
182
163
|
```
|
@@ -235,7 +216,7 @@ In your views:
|
|
235
216
|
#### `Showcase::Traits::Seo`
|
236
217
|
|
237
218
|
Useful to produce SEO meta tags (title, description, Facebook OpenGraph,
|
238
|
-
Twitter cards, and canonical
|
219
|
+
Twitter cards, and canonical URL):
|
239
220
|
|
240
221
|
```ruby
|
241
222
|
class ProjectPresenter < Showcase::Presenter
|
@@ -249,7 +230,6 @@ class ProjectPresenter < Showcase::Presenter
|
|
249
230
|
end
|
250
231
|
end
|
251
232
|
```
|
252
|
-
|
253
233
|
In your views:
|
254
234
|
|
255
235
|
```erb
|
data/Rakefile
CHANGED
@@ -1,14 +1 @@
|
|
1
|
-
require
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'appraisal'
|
4
|
-
|
5
|
-
desc 'Default: run specs'
|
6
|
-
task default: :spec
|
7
|
-
|
8
|
-
require 'rspec/core/rake_task'
|
9
|
-
RSpec::Core::RakeTask.new do |t|
|
10
|
-
t.pattern = "spec/**/*_spec.rb"
|
11
|
-
end
|
12
|
-
|
13
|
-
Bundler::GemHelper.install_tasks
|
14
|
-
|
1
|
+
require "bundler/gem_tasks"
|
@@ -12,40 +12,26 @@ module Showcase
|
|
12
12
|
title += options[:title_suffix] if options[:title_suffix]
|
13
13
|
|
14
14
|
context.content_tag(:title, title) <<
|
15
|
-
seo_meta_tags(
|
15
|
+
seo_meta_tags(:og_title, :twitter_title, values)
|
16
16
|
end
|
17
17
|
|
18
18
|
def description(values, options = {})
|
19
|
-
seo_meta_tags(
|
19
|
+
seo_meta_tags(:description, :og_description, :twitter_description, values)
|
20
20
|
end
|
21
21
|
|
22
22
|
def image_url(image_url, options = {})
|
23
|
-
seo_meta_tags(
|
24
|
-
end
|
25
|
-
|
26
|
-
def iframe_video_url(video_url, options = {})
|
27
|
-
seo_meta_tags('og:video:url', 'twitter:player', video_url) <<
|
28
|
-
seo_meta_tags('og:video:type', 'text/html')
|
29
|
-
end
|
30
|
-
|
31
|
-
def stream_video_url(video_url, options = {})
|
32
|
-
seo_meta_tags('og:video:url', 'twitter:player:stream', video_url) <<
|
33
|
-
seo_meta_tags('og:video:type', 'video/mp4')
|
34
|
-
end
|
35
|
-
|
36
|
-
def site_name(name, options = {})
|
37
|
-
seo_meta_tags('og:site_name', name)
|
23
|
+
seo_meta_tags(:og_image, :twitter_image, image_url)
|
38
24
|
end
|
39
25
|
|
40
26
|
def canonical_url(url, options = {})
|
41
|
-
seo_meta_tags(
|
27
|
+
seo_meta_tags(:og_url, url) <<
|
42
28
|
context.tag(:link, rel: "canonical", "href" => url)
|
43
29
|
end
|
44
30
|
|
45
31
|
private
|
46
32
|
|
47
33
|
def first_nonblank(values)
|
48
|
-
Array(values).
|
34
|
+
Array(values).map(&:presence).compact.first
|
49
35
|
end
|
50
36
|
|
51
37
|
def seo_meta_tags(*args)
|
@@ -54,14 +40,8 @@ module Showcase
|
|
54
40
|
return nil unless value.present?
|
55
41
|
|
56
42
|
args.map do |name|
|
57
|
-
|
58
|
-
|
59
|
-
'property'
|
60
|
-
else
|
61
|
-
'name'
|
62
|
-
end
|
63
|
-
name = chunks.join(':')
|
64
|
-
context.tag(:meta, attr_name => name, content: value)
|
43
|
+
name = name.to_s.sub(/_/, ":")
|
44
|
+
context.tag(:meta, name: name, content: value)
|
65
45
|
end.join.html_safe
|
66
46
|
end
|
67
47
|
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
|
data/lib/showcase/presenter.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
require 'delegate'
|
2
|
-
require 'showcase/helpers
|
3
|
-
require 'showcase/helpers/module_method_builder'
|
2
|
+
require 'showcase/helpers'
|
4
3
|
require 'active_support/core_ext/array/extract_options'
|
5
4
|
require 'active_support/core_ext/hash/keys'
|
6
5
|
|
7
6
|
module Showcase
|
8
7
|
class Presenter < SimpleDelegator
|
9
|
-
include Helpers
|
10
|
-
extend Helpers::ModuleMethodBuilder
|
8
|
+
include Helpers
|
11
9
|
|
12
10
|
attr_reader :view_context
|
13
11
|
|
14
12
|
alias_method :object, :__getobj__
|
15
13
|
alias_method :h, :view_context
|
16
14
|
alias_method :try, :__send__
|
17
|
-
alias_method :__decorator_class__, :class
|
18
15
|
|
19
16
|
def initialize(obj, context)
|
20
17
|
super(obj)
|
@@ -49,15 +46,19 @@ module Showcase
|
|
49
46
|
options.assert_valid_keys(:with, :nil_presenter)
|
50
47
|
presenter_klass = options.fetch(:with, nil)
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
49
|
+
methods_module = Module.new do
|
50
|
+
args.each do |attr|
|
51
|
+
define_method attr do
|
52
|
+
send(method,
|
53
|
+
object.send(attr),
|
54
|
+
presenter_klass,
|
55
|
+
view_context,
|
56
|
+
options.slice(:nil_presenter))
|
57
|
+
end
|
59
58
|
end
|
60
59
|
end
|
60
|
+
|
61
|
+
include(methods_module)
|
61
62
|
end
|
62
63
|
end
|
63
64
|
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
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/lib/showcase/traits/base.rb
CHANGED
@@ -3,9 +3,20 @@ module Showcase
|
|
3
3
|
module Base
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
+
define_method(method_name, &block)
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
8
18
|
end
|
19
|
+
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'showcase/helpers/config_object'
|
2
|
-
require 'showcase/helpers/html_options'
|
3
2
|
|
4
3
|
module Showcase
|
5
4
|
module Traits
|
@@ -10,24 +9,31 @@ module Showcase
|
|
10
9
|
|
11
10
|
module ClassMethods
|
12
11
|
def link_to(name = nil, &block)
|
13
|
-
|
12
|
+
|
13
|
+
define_method? [name, :url] do
|
14
14
|
Helpers::ConfigObject.new(self, &block).to_struct.url
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
define_method? [name, :link_active?] do
|
18
18
|
Helpers::ConfigObject.new(self, &block).to_struct.active
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
define_method? [name, :link] do |*args, &link_block|
|
22
22
|
config = Helpers::ConfigObject.new(self, &block).to_struct
|
23
|
+
options = args.extract_options!.symbolize_keys
|
24
|
+
options.reverse_merge!(config.html_options) if config.html_options
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
if config.active
|
27
|
+
options[:class] ||= ""
|
28
|
+
css_classes = options[:class].split(/\s+/)
|
29
|
+
css_classes << "active"
|
30
|
+
options[:class] = css_classes.join(" ")
|
31
|
+
end
|
27
32
|
|
28
33
|
args = Array(config.label) if args.empty? && !link_block
|
29
|
-
h.link_to *args, config.url,
|
34
|
+
h.link_to *args, config.url, options, &link_block
|
30
35
|
end
|
36
|
+
|
31
37
|
end
|
32
38
|
end
|
33
39
|
end
|
@@ -1,59 +1,35 @@
|
|
1
|
+
require 'action_view/record_identifier'
|
2
|
+
|
1
3
|
module Showcase
|
2
4
|
module Traits
|
3
5
|
|
4
6
|
module Record
|
5
7
|
extend ActiveSupport::Concern
|
6
8
|
|
7
|
-
module ClassMethods
|
8
|
-
def box(&block)
|
9
|
-
@box_config_block = block
|
10
|
-
end
|
11
|
-
|
12
|
-
def __box_config_block__
|
13
|
-
@box_config_block
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
9
|
def dom_id
|
18
|
-
|
10
|
+
ActionView::RecordIdentifier.dom_id(self)
|
19
11
|
end
|
20
12
|
|
21
13
|
def dom_class
|
22
|
-
|
14
|
+
ActiveModel::Naming.param_key(self)
|
23
15
|
end
|
24
16
|
|
25
17
|
def box(*args, &block)
|
26
18
|
options = args.extract_options!
|
19
|
+
options.symbolize_keys!
|
20
|
+
|
27
21
|
tag = args.pop || :div
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
{}
|
34
|
-
end
|
23
|
+
options[:class] ||= ""
|
24
|
+
css_classes = options[:class].split(/\s+/) << dom_class
|
25
|
+
options[:class] = css_classes.join(" ")
|
35
26
|
|
36
|
-
|
37
|
-
html_options.merge_attrs!(options)
|
38
|
-
html_options.add_class!(dom_class)
|
39
|
-
html_options.merge_attrs!(id: dom_id)
|
27
|
+
options[:id] = dom_id
|
40
28
|
|
41
|
-
h.content_tag(tag,
|
29
|
+
h.content_tag(tag, options) do
|
42
30
|
h.capture(self, &block)
|
43
31
|
end
|
44
32
|
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def record_identifier
|
49
|
-
if defined?(ActionView::RecordIdentifier)
|
50
|
-
ActionView::RecordIdentifier
|
51
|
-
elsif defined?(ActionController::RecordIdentifier)
|
52
|
-
ActionController::RecordIdentifier
|
53
|
-
else
|
54
|
-
raise 'No RecordIdentifier found!'
|
55
|
-
end
|
56
|
-
end
|
57
33
|
end
|
58
34
|
|
59
35
|
end
|
data/lib/showcase/traits/seo.rb
CHANGED
@@ -9,27 +9,13 @@ 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
|
-
|
18
12
|
def seo(name = nil, options = {}, &block)
|
19
|
-
|
20
|
-
meta =
|
21
|
-
meta.merge!(Helpers::ConfigObject.new(self, &block).to_hash)
|
22
|
-
meta.merge!(options.symbolize_keys) if options
|
23
|
-
|
13
|
+
define_method? [name, :seo_tags] do |options = {}|
|
14
|
+
meta = Helpers::ConfigObject.new(self, &block).to_hash
|
24
15
|
builder = Helpers::SeoMetaBuilder.new(view_context)
|
25
|
-
parts = %w(
|
26
|
-
title description site_name
|
27
|
-
canonical_url
|
28
|
-
image_url iframe_video_url stream_video_url
|
29
|
-
).map(&:to_sym)
|
30
|
-
|
16
|
+
parts = %w(title description canonical_url image_url canonical_url).map(&:to_sym)
|
31
17
|
parts.map do |tag|
|
32
|
-
builder.send(tag, meta[tag],
|
18
|
+
builder.send(tag, meta[tag], options) if meta[tag]
|
33
19
|
end.compact.join.html_safe
|
34
20
|
end
|
35
21
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'showcase/helpers/config_object'
|
2
|
-
require 'active_support/core_ext/object/to_query'
|
3
2
|
|
4
3
|
module Showcase
|
5
4
|
module Traits
|
@@ -42,17 +41,14 @@ module Showcase
|
|
42
41
|
|
43
42
|
link_to link_name do |c|
|
44
43
|
meta = Helpers::ConfigObject.new(self, &block).to_struct
|
45
|
-
html_options = meta.html_options || {}
|
46
44
|
params = Hash[
|
47
45
|
settings[:params].map do |param, meta_key|
|
48
|
-
|
49
|
-
[ param, values.find(&:presence) ]
|
46
|
+
[ param, meta.send(meta_key) ]
|
50
47
|
end
|
51
48
|
]
|
52
|
-
|
53
49
|
c.url "#{settings[:url]}?#{params.to_query}"
|
54
50
|
c.label settings[:label]
|
55
|
-
c.html_options =
|
51
|
+
c.html_options = { target: :blank }
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
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@welaika.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
@@ -13,8 +13,8 @@ module Showcase::Helpers
|
|
13
13
|
expect(subject.title('foo')).to have_tag(:title, text: 'foo')
|
14
14
|
end
|
15
15
|
|
16
|
-
it 'produces a
|
17
|
-
expect(subject.title('foo')).to have_tag(:meta, with: {
|
16
|
+
it 'produces a ug:title meta tag' do
|
17
|
+
expect(subject.title('foo')).to have_tag(:meta, with: { name: 'og:title', content: 'foo' })
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'produces a twitter:title meta tag' do
|
@@ -32,7 +32,7 @@ module Showcase::Helpers
|
|
32
32
|
expect(subject.title('foo', title_suffix: ' - bar')).to have_tag(:title, text: 'foo - bar')
|
33
33
|
end
|
34
34
|
it 'does not suffix meta tags' do
|
35
|
-
expect(subject.title('foo')).to have_tag(:meta, with: {
|
35
|
+
expect(subject.title('foo')).to have_tag(:meta, with: { name: 'og:title', content: 'foo' })
|
36
36
|
expect(subject.title('foo')).to have_tag(:meta, with: { name: 'twitter:title', content: 'foo' })
|
37
37
|
end
|
38
38
|
end
|
@@ -44,7 +44,7 @@ module Showcase::Helpers
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'produces a og:description meta tag' do
|
47
|
-
expect(subject.description('foo')).to have_tag(:meta, with: {
|
47
|
+
expect(subject.description('foo')).to have_tag(:meta, with: { name: 'og:description', content: 'foo' })
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'produces a twitter:description meta tag' do
|
@@ -60,7 +60,7 @@ module Showcase::Helpers
|
|
60
60
|
|
61
61
|
describe '#image_url' do
|
62
62
|
it 'produces a og:image meta tag' do
|
63
|
-
expect(subject.image_url('foo')).to have_tag(:meta, with: {
|
63
|
+
expect(subject.image_url('foo')).to have_tag(:meta, with: { name: 'og:image', content: 'foo' })
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'produces a twitter:image meta tag' do
|
@@ -69,14 +69,14 @@ module Showcase::Helpers
|
|
69
69
|
|
70
70
|
context 'with multiple values' do
|
71
71
|
it 'uses the first non-blank' do
|
72
|
-
expect(subject.image_url(['', nil, 'foo'])).to have_tag(:meta, with: {
|
72
|
+
expect(subject.image_url(['', nil, 'foo'])).to have_tag(:meta, with: { name: 'og:image', content: 'foo' })
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
describe '#canonical_url' do
|
78
78
|
it 'produces a og:url meta tag' do
|
79
|
-
expect(subject.canonical_url('foo')).to have_tag(:meta, with: {
|
79
|
+
expect(subject.canonical_url('foo')).to have_tag(:meta, with: { name: 'og:url', content: 'foo' })
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'produces a canonical link tag' do
|
@@ -85,44 +85,11 @@ module Showcase::Helpers
|
|
85
85
|
|
86
86
|
context 'with multiple values' do
|
87
87
|
it 'uses the first non-blank' do
|
88
|
-
expect(subject.canonical_url(['', nil, 'foo'])).to have_tag(:meta, with: {
|
88
|
+
expect(subject.canonical_url(['', nil, 'foo'])).to have_tag(:meta, with: { name: 'og:url', content: 'foo' })
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
describe '#iframe_video_url' do
|
94
|
-
it 'produces a og:video:url meta tag' do
|
95
|
-
expect(subject.iframe_video_url('foo')).to have_tag(:meta, with: { property: 'og:video:url', content: 'foo' })
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'produces a twitter:player meta tag' do
|
99
|
-
expect(subject.iframe_video_url('foo')).to have_tag(:meta, with: { name: 'twitter:player', content: 'foo' })
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'produces a og:video:type meta tag' do
|
103
|
-
expect(subject.iframe_video_url('foo')).to have_tag(:meta, with: { property: 'og:video:type', content: 'text/html' })
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe '#stream_video_url' do
|
108
|
-
it 'produces a og:video:url meta tag' do
|
109
|
-
expect(subject.stream_video_url('foo')).to have_tag(:meta, with: { property: 'og:video:url', content: 'foo' })
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'produces a twitter:player:stream meta tag' do
|
113
|
-
expect(subject.stream_video_url('foo')).to have_tag(:meta, with: { name: 'twitter:player:stream', content: 'foo' })
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'produces a og:video:type meta tag' do
|
117
|
-
expect(subject.stream_video_url('foo')).to have_tag(:meta, with: { property: 'og:video:type', content: 'video/mp4' })
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '#site_name' do
|
122
|
-
it 'produces a og:site_name meta tag' do
|
123
|
-
expect(subject.site_name('foo')).to have_tag(:meta, with: { property: 'og:site_name', content: 'foo' })
|
124
|
-
end
|
125
|
-
end
|
126
93
|
end
|
127
94
|
end
|
128
95
|
|
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_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_method? :foo do
|
11
11
|
true
|
12
12
|
end
|
13
13
|
end
|
@@ -15,22 +15,6 @@ module Showcase::Traits
|
|
15
15
|
expect(klass.new.foo).to be_true
|
16
16
|
end
|
17
17
|
|
18
|
-
it 'overriding the method allows to call super' do
|
19
|
-
klass = Class.new do
|
20
|
-
include Base
|
21
|
-
|
22
|
-
define_module_method :foo do
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
|
-
def foo
|
27
|
-
super
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
expect(klass.new.foo).to be_true
|
32
|
-
end
|
33
|
-
|
34
18
|
context 'if the method is already present' do
|
35
19
|
it 'no-ops ' do
|
36
20
|
klass = Class.new do
|
@@ -46,7 +30,7 @@ module Showcase::Traits
|
|
46
30
|
it 'joins them in snake case' do
|
47
31
|
klass = Class.new do
|
48
32
|
include Base
|
49
|
-
|
33
|
+
define_method? [:foo, :bar] do
|
50
34
|
true
|
51
35
|
end
|
52
36
|
end
|
@@ -57,7 +41,7 @@ module Showcase::Traits
|
|
57
41
|
it 'ignores blank chunks' do
|
58
42
|
klass = Class.new do
|
59
43
|
include Base
|
60
|
-
|
44
|
+
define_method? ["", :bar] do
|
61
45
|
true
|
62
46
|
end
|
63
47
|
end
|
data/spec/traits/link_to_spec.rb
CHANGED
@@ -20,13 +20,10 @@ module Showcase::Traits
|
|
20
20
|
c.url = url
|
21
21
|
c.label = 'Label'
|
22
22
|
c.active = active
|
23
|
-
c.html_options role: 'label'
|
24
23
|
end
|
25
24
|
|
26
|
-
link_to :foo do
|
25
|
+
link_to :foo do
|
27
26
|
c.url = '#foo'
|
28
|
-
c.active_class = 'current'
|
29
|
-
c.active = active
|
30
27
|
end
|
31
28
|
|
32
29
|
def url
|
@@ -46,10 +43,6 @@ module Showcase::Traits
|
|
46
43
|
expect(subject.link).to have_tag(:a, text: 'Label')
|
47
44
|
end
|
48
45
|
|
49
|
-
it 'with the specified html attributes' do
|
50
|
-
expect(subject.link).to have_tag(:a, with: { role: 'label' })
|
51
|
-
end
|
52
|
-
|
53
46
|
context 'with a different label as parameter' do
|
54
47
|
it 'uses it' do
|
55
48
|
expect(subject.link('Foo')).to have_tag(:a, text: 'Foo')
|
@@ -72,18 +65,12 @@ module Showcase::Traits
|
|
72
65
|
let(:active) { true }
|
73
66
|
|
74
67
|
it 'adds an active class to the link' do
|
75
|
-
expect(subject.link
|
68
|
+
expect(subject.link).to have_tag(:a, with: { class: 'active' })
|
76
69
|
end
|
77
70
|
|
78
71
|
context 'with additional classes' do
|
79
72
|
it 'it sums them' do
|
80
|
-
expect(subject.link(
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'if a different CSS class was specified' do
|
85
|
-
it 'adds it to the link' do
|
86
|
-
expect(subject.foo_link('label')).to have_tag(:a, with: { class: 'current' })
|
73
|
+
expect(subject.link(class: 'extra')).to have_tag(:a, with: { class: 'extra active' })
|
87
74
|
end
|
88
75
|
end
|
89
76
|
end
|
data/spec/traits/record_spec.rb
CHANGED
@@ -8,10 +8,6 @@ module Showcase::Traits
|
|
8
8
|
let(:presenter) {
|
9
9
|
Class.new(Showcase::Presenter) do
|
10
10
|
include Record
|
11
|
-
|
12
|
-
box do |c|
|
13
|
-
c.html_options role: 'actor', class: 'first'
|
14
|
-
end
|
15
11
|
end
|
16
12
|
}
|
17
13
|
subject { presenter.new(record, view) }
|
@@ -34,11 +30,6 @@ module Showcase::Traits
|
|
34
30
|
expect(result).to have_tag(:div, with: { class: 'model', id: 'model_1' })
|
35
31
|
end
|
36
32
|
|
37
|
-
it 'adds attributes specified within box block' do
|
38
|
-
result = subject.box { "foo" }
|
39
|
-
expect(result).to have_tag(:div, with: { role: 'actor', class: 'first' })
|
40
|
-
end
|
41
|
-
|
42
33
|
context 'with a specified tag' do
|
43
34
|
it 'uses it' do
|
44
35
|
result = subject.box(:span) { "foo" }
|
data/spec/traits/seo_spec.rb
CHANGED
@@ -12,10 +12,6 @@ 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
|
-
|
19
15
|
seo do |c|
|
20
16
|
c.title = 'foo'
|
21
17
|
c.description 'bar'
|
@@ -23,27 +19,16 @@ module Showcase::Traits
|
|
23
19
|
end
|
24
20
|
}
|
25
21
|
|
26
|
-
describe '
|
27
|
-
let(:
|
28
|
-
let(:expected_description) { 'bar' }
|
29
|
-
let(:expected_title) { 'foo' }
|
30
|
-
|
22
|
+
describe '#seo' do
|
23
|
+
let(:options) { double('options') }
|
31
24
|
before do
|
32
25
|
Showcase::Helpers::SeoMetaBuilder.stub(:new).with(view).and_return(builder)
|
33
|
-
builder.stub(:title).with(
|
34
|
-
builder.stub(:description).with(
|
26
|
+
builder.stub(:title).with('foo', options).and_return('<title>')
|
27
|
+
builder.stub(:description).with('bar', options).and_return('<description>')
|
35
28
|
end
|
36
29
|
|
37
30
|
it 'defines a seo_tags method that ouputs seo meta tags' do
|
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
|
31
|
+
expect(subject.seo_tags(options)).to eq '<title><description>'
|
47
32
|
end
|
48
33
|
end
|
49
34
|
|
data/spec/traits/share_spec.rb
CHANGED
@@ -14,9 +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'
|
18
17
|
c.image_url = 'image'
|
19
|
-
c.html_options = { role: 'share' }
|
20
18
|
end
|
21
19
|
|
22
20
|
share :foo do |c|
|
@@ -30,7 +28,7 @@ module Showcase::Traits
|
|
30
28
|
|
31
29
|
describe '#social_share' do
|
32
30
|
expected_urls = {
|
33
|
-
twitter: "https://twitter.com/intent/tweet?text=
|
31
|
+
twitter: "https://twitter.com/intent/tweet?text=text&url=url",
|
34
32
|
facebook: "http://www.facebook.com/sharer/sharer.php?u=url",
|
35
33
|
gplus: "https://plus.google.com/share?url=url",
|
36
34
|
pinterest: "http://www.pinterest.com/pin/create/button/?media=image&title=text&url=url",
|
@@ -41,19 +39,10 @@ module Showcase::Traits
|
|
41
39
|
it "produces a #{provider} share link" do
|
42
40
|
expect(subject.send("#{provider}_share_link")).to have_tag(:a)
|
43
41
|
end
|
44
|
-
|
45
42
|
it "produces a #{provider} share url" do
|
46
43
|
expect(subject.send("#{provider}_share_url")).to eq url
|
47
44
|
end
|
48
45
|
|
49
|
-
it "adds a target :blank to the link" do
|
50
|
-
expect(subject.send("#{provider}_share_link")).to have_tag(:a, with: { target: '_blank' })
|
51
|
-
end
|
52
|
-
|
53
|
-
it "merges additional html_options" do
|
54
|
-
expect(subject.send("#{provider}_share_link")).to have_tag(:a, with: { role: 'share' })
|
55
|
-
end
|
56
|
-
|
57
46
|
context 'with prefix' do
|
58
47
|
it 'prefixes link method' do
|
59
48
|
expect(subject).to respond_to "foo_#{provider}_share_link"
|
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.
|
4
|
+
version: 0.2.0.pre
|
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-09-21 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@welaika.com
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
@@ -90,21 +90,16 @@ files:
|
|
90
90
|
- .gitignore
|
91
91
|
- .rspec
|
92
92
|
- .travis.yml
|
93
|
-
- Appraisals
|
94
93
|
- Gemfile
|
95
94
|
- LICENSE.txt
|
96
95
|
- README.md
|
97
96
|
- Rakefile
|
98
|
-
- gemfiles/rails_32.gemfile
|
99
|
-
- gemfiles/rails_4.gemfile
|
100
97
|
- lib/generators/showcase/presenter/USAGE
|
101
98
|
- lib/generators/showcase/presenter/presenter_generator.rb
|
102
99
|
- lib/generators/showcase/presenter/templates/presenter.rb
|
103
100
|
- lib/showcase.rb
|
101
|
+
- lib/showcase/helpers.rb
|
104
102
|
- lib/showcase/helpers/config_object.rb
|
105
|
-
- lib/showcase/helpers/html_options.rb
|
106
|
-
- lib/showcase/helpers/module_method_builder.rb
|
107
|
-
- lib/showcase/helpers/present.rb
|
108
103
|
- lib/showcase/helpers/seo_meta_builder.rb
|
109
104
|
- lib/showcase/presenter.rb
|
110
105
|
- lib/showcase/railtie.rb
|
data/Appraisals
DELETED
data/gemfiles/rails_32.gemfile
DELETED
data/gemfiles/rails_4.gemfile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class HtmlOptions
|
2
|
-
def initialize(options = {})
|
3
|
-
@options = (options || {}).symbolize_keys
|
4
|
-
end
|
5
|
-
|
6
|
-
def add_class!(css_class)
|
7
|
-
@options[:class] ||= ""
|
8
|
-
css_classes = @options[:class].split(/\s+/)
|
9
|
-
css_classes << css_class
|
10
|
-
@options[:class] = css_classes.join(" ")
|
11
|
-
end
|
12
|
-
|
13
|
-
def merge_attrs!(options = {})
|
14
|
-
options = (options || {}).symbolize_keys
|
15
|
-
@options.merge!(options)
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_h
|
19
|
-
@options.dup
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
@@ -1,19 +0,0 @@
|
|
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
|
-
|
@@ -1,35 +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
|
-
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
|
-
|