keynote 0.1.3 → 0.2.0pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of keynote might be problematic. Click here for more details.
- data/CHANGELOG.md +11 -0
- data/keynote.gemspec +1 -1
- data/lib/generators/presenter_generator.rb +10 -7
- data/lib/generators/templates/keynote_mini_test_spec.rb +9 -7
- data/lib/generators/templates/keynote_mini_test_unit.rb +2 -2
- data/lib/generators/templates/keynote_rspec.rb +9 -1
- data/lib/generators/templates/keynote_test_unit.rb +1 -1
- data/lib/keynote.rb +1 -1
- data/lib/keynote/presenter.rb +6 -0
- data/lib/keynote/railtie.rb +8 -2
- data/lib/keynote/rumble.rb +9 -13
- data/lib/keynote/testing/minitest_rails.rake +18 -2
- data/lib/keynote/testing/minitest_rails.rb +18 -13
- data/lib/keynote/testing/rspec.rb +3 -0
- data/lib/keynote/testing/test_present_method.rb +10 -0
- data/lib/keynote/testing/test_unit.rb +3 -0
- data/lib/keynote/version.rb +1 -1
- data/spec/generator_spec.rb +1 -1
- data/spec/helper.rb +10 -0
- data/spec/presenter_spec.rb +14 -0
- metadata +25 -24
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
## v0.2.0pre1
|
2
|
+
* Add an implementation of the `present`/`k` method that's available in test
|
3
|
+
cases. Update test generators accordingly.
|
4
|
+
* Update minitest-rails integration to be compatible with the newest
|
5
|
+
version of minitest-rails (on Rails 3.0, 3.1, 3.2, and 4.0).
|
6
|
+
* Add `use_html_5_tags` class method to `Keynote::Presenter`. This adds a more
|
7
|
+
complete set of Rumble tag methods to the class.
|
8
|
+
|
9
|
+
## v0.1.3
|
10
|
+
* Add block form of `present`. If you pass a block into a `present` call, it
|
11
|
+
yields the presenter.
|
data/keynote.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
A presenter is an object that encapsulates view logic. Like Rails helpers,
|
10
10
|
presenters help you keep complex logic out of your templates. Keynote
|
11
11
|
provides a consistent interface for defining and instantiating presenters.
|
12
|
-
}
|
12
|
+
}.gsub(/\s+/, ' ')
|
13
13
|
gem.homepage = "https://github.com/rf-/keynote"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($\)
|
@@ -20,6 +20,9 @@ module Rails::Generators
|
|
20
20
|
when :rspec
|
21
21
|
template 'keynote_rspec.rb', rspec_path
|
22
22
|
when :test_unit
|
23
|
+
# In Rails 4 this is kind of a weird place to generate tests into.
|
24
|
+
# Unfortunately it isn't really fixable without changing the Rails
|
25
|
+
# test tasks, so that's a TODO.
|
23
26
|
template 'keynote_test_unit.rb', test_unit_path
|
24
27
|
when :mini_test
|
25
28
|
if Rails.application.config.generators.mini_test[:spec]
|
@@ -51,17 +54,17 @@ module Rails::Generators
|
|
51
54
|
targets.map { |t| ":#{t}" }.join(', ')
|
52
55
|
end
|
53
56
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
def presenter_name_and_target_list
|
58
|
+
[presenter_name, *target_list].join(', ')
|
59
|
+
end
|
60
|
+
|
61
|
+
def presenter_name
|
62
|
+
class_name.sub(/Presenter$/, '').underscore.to_sym.inspect
|
60
63
|
end
|
61
64
|
|
62
65
|
if ::Rails.version.to_f < 3.1
|
63
66
|
protected
|
64
|
-
# This
|
67
|
+
# This method doesn't exist in Rails 3.0
|
65
68
|
def module_namespacing
|
66
69
|
yield if block_given?
|
67
70
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require "minitest_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# Specs in this file have access to the present (or k) method, which they can
|
4
|
+
# use to instantiate <%= class_name %>Presenter as normal. For example:
|
5
|
+
#
|
6
|
+
# describe <%= class_name %>Presenter do
|
7
|
+
# it "has access to a view" do
|
8
|
+
# k(<%= presenter_name_and_target_list %>).should respond_to(:view)
|
9
|
+
# end
|
10
|
+
# end
|
7
11
|
|
8
|
-
|
9
|
-
# flunk "Need real tests"
|
10
|
-
# end
|
12
|
+
describe <%= class_name %>Presenter do
|
11
13
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
|
3
|
-
class <%= class_name %>PresenterTest < Keynote::
|
3
|
+
class <%= class_name %>PresenterTest < Keynote::TestCase
|
4
4
|
setup do
|
5
|
-
@presenter =
|
5
|
+
@presenter = present(<%= presenter_name_and_target_list %>)
|
6
6
|
end
|
7
7
|
|
8
8
|
# test "the truth" do
|
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# Specs in this file have access to the present (or k) method, which they can
|
4
|
+
# use to instantiate <%= class_name %>Presenter as normal. For example:
|
5
|
+
#
|
6
|
+
# describe <%= class_name %>Presenter do
|
7
|
+
# it "has access to a view" do
|
8
|
+
# k(<%= presenter_name_and_target_list %>).should respond_to(:view)
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
|
3
12
|
describe <%= class_name %>Presenter do
|
4
|
-
subject { <%= class_name %>Presenter.new(<%= view_and_target_list %>) }
|
5
13
|
end
|
data/lib/keynote.rb
CHANGED
@@ -26,7 +26,7 @@ module Keynote
|
|
26
26
|
# @see Keynote::Controller#present
|
27
27
|
# @see Keynote::Presenter#present
|
28
28
|
#
|
29
|
-
# @overload present(*objects)
|
29
|
+
# @overload present(view, *objects)
|
30
30
|
# Return a presenter wrapping the given objects. The type of the
|
31
31
|
# presenter will be inferred from the type of the first object.
|
32
32
|
# @example
|
data/lib/keynote/presenter.rb
CHANGED
@@ -41,6 +41,12 @@ module Keynote
|
|
41
41
|
end # end
|
42
42
|
RUBY
|
43
43
|
end
|
44
|
+
|
45
|
+
# Define a more complete set of HTML5 tag methods. The extra tags are
|
46
|
+
# listed in {Keynote::Rumble::COMPLETE}.
|
47
|
+
def use_html_5_tags
|
48
|
+
Rumble.use_html_5_tags(self)
|
49
|
+
end
|
44
50
|
end
|
45
51
|
|
46
52
|
# @private (used by Keynote::Cache to keep the view context up-to-date)
|
data/lib/keynote/railtie.rb
CHANGED
@@ -6,7 +6,11 @@ module Keynote
|
|
6
6
|
# @private
|
7
7
|
class Railtie < Rails::Railtie
|
8
8
|
config.after_initialize do |app|
|
9
|
-
|
9
|
+
if ::Rails.version.to_f >= 4
|
10
|
+
app.config.paths.add 'app/presenters'
|
11
|
+
else
|
12
|
+
app.config.paths.add 'app/presenters', :eager_load => true
|
13
|
+
end
|
10
14
|
|
11
15
|
if defined?(RSpec::Rails) && RSpec.respond_to?(:configure)
|
12
16
|
require 'keynote/testing/rspec'
|
@@ -16,7 +20,9 @@ module Keynote
|
|
16
20
|
require 'keynote/testing/minitest_rails'
|
17
21
|
end
|
18
22
|
|
19
|
-
|
23
|
+
if !defined?(MiniTest::Rails)
|
24
|
+
require "keynote/testing/test_unit"
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
ActiveSupport.on_load(:action_view) do
|
data/lib/keynote/rumble.rb
CHANGED
@@ -167,16 +167,14 @@ module Keynote
|
|
167
167
|
table tbody td textarea tfoot th thead time tr ul]
|
168
168
|
|
169
169
|
# A more complete set of HTML5 tags. You can use these by calling
|
170
|
-
# `
|
171
|
-
COMPLETE = %w[
|
172
|
-
basefont bdo big blockquote body
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
select small source span strike strong style sub summary sup table tbody
|
179
|
-
td textarea tfoot th thead time title tr tt u ul var video wbr xmp]
|
170
|
+
# `use_html_5_tags` in a presenter's class body.
|
171
|
+
COMPLETE = %w[abbr acronym address applet area article aside audio base
|
172
|
+
basefont bdo big blockquote body canvas caption center cite code col
|
173
|
+
colgroup command datalist dd details dfn dir dl dt embed fieldset
|
174
|
+
figcaption figure font footer frame frameset head header hgroup iframe
|
175
|
+
ins keygen kbd legend map mark menu meta meter nav noframes noscript
|
176
|
+
object output param progress q rp rt ruby s samp section small source
|
177
|
+
strike style summary title tt u var video wbr xmp]
|
180
178
|
|
181
179
|
# @private
|
182
180
|
SELFCLOSING = %w[base meta link hr br param img area input col frame]
|
@@ -199,9 +197,7 @@ module Keynote
|
|
199
197
|
end
|
200
198
|
end
|
201
199
|
|
202
|
-
#
|
203
|
-
# class.
|
204
|
-
# @param [Keynote::Presenter] base
|
200
|
+
# @private
|
205
201
|
def self.use_html_5_tags(base)
|
206
202
|
define_tags(base, COMPLETE)
|
207
203
|
end
|
@@ -1,2 +1,18 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "rake/testtask"
|
4
|
+
require "minitest/rails/testing"
|
5
|
+
require "minitest/rails/tasks/sub_test_task"
|
6
|
+
|
7
|
+
MiniTest::Rails::Testing.default_tasks << "presenters"
|
8
|
+
|
9
|
+
namespace "minitest" do
|
10
|
+
unless Rake::Task.task_defined? "minitest:presenters"
|
11
|
+
desc "Runs tests under test/presenters"
|
12
|
+
MiniTest::Rails::Tasks::SubTestTask.new("presenters" => "test:prepare") do |t|
|
13
|
+
t.libs.push "test"
|
14
|
+
t.pattern = "test/presenters/**/*_test.rb"
|
15
|
+
t.options = MiniTest::Rails::Testing.task_opts["presenters"] if MiniTest::Rails::Testing.task_opts["presenters"]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,22 +1,27 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Mutually exclusive with the Keynote::TestCase defined in
|
4
|
+
# keynote/testing/test_unit. This is kind of icky but consistent with how
|
5
|
+
# MT::R itself replaces the Rails test case classes.
|
6
|
+
|
7
|
+
require "minitest/rails"
|
8
|
+
require "keynote/testing/test_present_method"
|
4
9
|
|
5
10
|
module Keynote
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
class TestCase < ::ActionView::TestCase
|
12
|
+
include TestPresentMethod
|
13
|
+
|
14
|
+
# describe SomePresenter do
|
15
|
+
register_spec_type(self) do |desc|
|
16
|
+
desc < Keynote::Presenter if desc.is_a?(Class)
|
17
|
+
end
|
12
18
|
|
13
|
-
|
14
|
-
|
19
|
+
# describe "SomePresenter" do
|
20
|
+
register_spec_type(/presenter( ?test)?\z/i, self)
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
22
|
+
# Don't try to include any particular helper, since we're not testing one
|
23
|
+
def self.include_helper_modules!
|
24
|
+
include _helpers
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
+
require "keynote/testing/test_present_method"
|
4
|
+
|
3
5
|
module Keynote
|
4
6
|
module ExampleGroup
|
5
7
|
def self.included(base)
|
6
8
|
base.send :include, RSpec::Rails::ViewExampleGroup
|
9
|
+
base.send :include, TestPresentMethod
|
7
10
|
base.metadata[:type] = :presenter
|
8
11
|
end
|
9
12
|
end
|
data/lib/keynote/version.rb
CHANGED
data/spec/generator_spec.rb
CHANGED
@@ -100,7 +100,7 @@ describe "generators" do
|
|
100
100
|
must_match /class PostPresenter < Keynote::Presenter/
|
101
101
|
|
102
102
|
file_contents('test/presenters/post_presenter_test.rb').
|
103
|
-
must_match /class PostPresenterTest < Keynote::
|
103
|
+
must_match /class PostPresenterTest < Keynote::TestCase/
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
data/spec/helper.rb
CHANGED
@@ -82,3 +82,13 @@ end
|
|
82
82
|
class CombinedPresenter < Keynote::Presenter
|
83
83
|
presents :model_1, :model_2
|
84
84
|
end
|
85
|
+
|
86
|
+
class Html5Presenter < Keynote::Presenter
|
87
|
+
def generate_h3(content)
|
88
|
+
build_html { h3 content }
|
89
|
+
end
|
90
|
+
|
91
|
+
def generate_small(content)
|
92
|
+
build_html { small content }
|
93
|
+
end
|
94
|
+
end
|
data/spec/presenter_spec.rb
CHANGED
@@ -62,6 +62,20 @@ describe Keynote::Presenter do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
describe ".use_html5_tags" do
|
66
|
+
it "should add Rumble tags like `small` while preserving existing tags" do
|
67
|
+
presenter = Html5Presenter.new(nil)
|
68
|
+
|
69
|
+
presenter.generate_h3("hi").must_equal "<h3>hi</h3>"
|
70
|
+
proc { presenter.generate_small("uh-oh") }.must_raise NoMethodError
|
71
|
+
|
72
|
+
Html5Presenter.use_html_5_tags
|
73
|
+
|
74
|
+
presenter.generate_h3("hi").must_equal "<h3>hi</h3>"
|
75
|
+
presenter.generate_small("hi").must_equal "<small>hi</small>"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
65
79
|
describe "#present" do
|
66
80
|
it "should pass its view context through to the new presenter" do
|
67
81
|
mock = mock()
|
metadata
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keynote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.
|
4
|
+
prerelease: 5
|
5
|
+
version: 0.2.0pre1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Fitzgerald
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
15
16
|
version_requirements: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - ! '>='
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: 3.0.0
|
20
21
|
none: false
|
21
|
-
name: rails
|
22
22
|
type: :runtime
|
23
|
-
|
23
|
+
name: rails
|
24
24
|
requirement: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ! '>='
|
@@ -28,15 +28,15 @@ dependencies:
|
|
28
28
|
version: 3.0.0
|
29
29
|
none: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
+
prerelease: false
|
31
32
|
version_requirements: !ruby/object:Gem::Requirement
|
32
33
|
requirements:
|
33
34
|
- - ! '>='
|
34
35
|
- !ruby/object:Gem::Version
|
35
36
|
version: '0'
|
36
37
|
none: false
|
37
|
-
name: appraisal
|
38
38
|
type: :development
|
39
|
-
|
39
|
+
name: appraisal
|
40
40
|
requirement: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,15 +44,15 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
none: false
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
+
prerelease: false
|
47
48
|
version_requirements: !ruby/object:Gem::Requirement
|
48
49
|
requirements:
|
49
50
|
- - ! '>='
|
50
51
|
- !ruby/object:Gem::Version
|
51
52
|
version: '0'
|
52
53
|
none: false
|
53
|
-
name: minitest
|
54
54
|
type: :development
|
55
|
-
|
55
|
+
name: minitest
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - ! '>='
|
@@ -60,15 +60,15 @@ dependencies:
|
|
60
60
|
version: '0'
|
61
61
|
none: false
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
+
prerelease: false
|
63
64
|
version_requirements: !ruby/object:Gem::Requirement
|
64
65
|
requirements:
|
65
66
|
- - ! '>='
|
66
67
|
- !ruby/object:Gem::Version
|
67
68
|
version: '0'
|
68
69
|
none: false
|
69
|
-
name: mocha
|
70
70
|
type: :development
|
71
|
-
|
71
|
+
name: mocha
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,15 +76,15 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
none: false
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
+
prerelease: false
|
79
80
|
version_requirements: !ruby/object:Gem::Requirement
|
80
81
|
requirements:
|
81
82
|
- - ! '>='
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
85
|
none: false
|
85
|
-
name: pry
|
86
86
|
type: :development
|
87
|
-
|
87
|
+
name: pry
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
90
|
- - ! '>='
|
@@ -92,15 +92,15 @@ dependencies:
|
|
92
92
|
version: '0'
|
93
93
|
none: false
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
+
prerelease: false
|
95
96
|
version_requirements: !ruby/object:Gem::Requirement
|
96
97
|
requirements:
|
97
98
|
- - ! '>='
|
98
99
|
- !ruby/object:Gem::Version
|
99
100
|
version: '0'
|
100
101
|
none: false
|
101
|
-
name: redcarpet
|
102
102
|
type: :development
|
103
|
-
|
103
|
+
name: redcarpet
|
104
104
|
requirement: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
106
|
- - ! '>='
|
@@ -108,25 +108,24 @@ dependencies:
|
|
108
108
|
version: '0'
|
109
109
|
none: false
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
+
prerelease: false
|
111
112
|
version_requirements: !ruby/object:Gem::Requirement
|
112
113
|
requirements:
|
113
114
|
- - ! '>='
|
114
115
|
- !ruby/object:Gem::Version
|
115
116
|
version: '0'
|
116
117
|
none: false
|
117
|
-
name: yard
|
118
118
|
type: :development
|
119
|
-
|
119
|
+
name: yard
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ! '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
none: false
|
126
|
-
description: !
|
127
|
-
|
128
|
-
|
129
|
-
\ "
|
126
|
+
description: ! ' A presenter is an object that encapsulates view logic. Like Rails
|
127
|
+
helpers, presenters help you keep complex logic out of your templates. Keynote provides
|
128
|
+
a consistent interface for defining and instantiating presenters. '
|
130
129
|
email:
|
131
130
|
- rwfitzge@gmail.com
|
132
131
|
executables: []
|
@@ -136,6 +135,7 @@ files:
|
|
136
135
|
- .gitignore
|
137
136
|
- .yardopts
|
138
137
|
- Appraisals
|
138
|
+
- CHANGELOG.md
|
139
139
|
- Gemfile
|
140
140
|
- LICENSE
|
141
141
|
- README.md
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/keynote/testing/minitest_rails.rake
|
158
158
|
- lib/keynote/testing/minitest_rails.rb
|
159
159
|
- lib/keynote/testing/rspec.rb
|
160
|
+
- lib/keynote/testing/test_present_method.rb
|
160
161
|
- lib/keynote/testing/test_unit.rb
|
161
162
|
- lib/keynote/version.rb
|
162
163
|
- spec/generator_spec.rb
|
@@ -180,13 +181,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
180
181
|
none: false
|
181
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
183
|
requirements:
|
183
|
-
- - ! '
|
184
|
+
- - ! '>'
|
184
185
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
186
|
+
version: 1.3.1
|
186
187
|
none: false
|
187
188
|
requirements: []
|
188
189
|
rubyforge_project:
|
189
|
-
rubygems_version: 1.8.
|
190
|
+
rubygems_version: 1.8.25
|
190
191
|
signing_key:
|
191
192
|
specification_version: 3
|
192
193
|
summary: Flexible presenters for Rails.
|