keynote 0.2.0pre2 → 0.2.0pre3
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.
- checksums.yaml +8 -8
- data/gemfiles/rails30.gemfile.lock +1 -1
- data/gemfiles/rails31.gemfile.lock +1 -1
- data/gemfiles/rails32.gemfile.lock +1 -1
- data/gemfiles/rails4.gemfile.lock +1 -1
- data/lib/keynote/inline.rb +63 -27
- data/lib/keynote/railtie.rb +24 -17
- data/lib/keynote/version.rb +1 -1
- data/spec/benchmarks.rb +1 -0
- data/spec/inline_spec.rb +6 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzFlYTA4N2M3ZDE3NjA0MGNlZTgxYjI2YTJiZjAyNWYyMTMwODUyMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzgwNTJmNzhiMjZjOTBmMTkxZDg0MWE0NzVkZDE0NzhmNDA3NjAwNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmIzNThlN2FhNWM0OGZjNTdjZmQ5MTJjYWZmMTAzZjAwYjBjYzA3MWM4Nzdh
|
10
|
+
NDJhZDg5NjgxNjY2NTI0MTNjMDc0ZjdkYzNlYjFhNmVlMTNmNTYwZjM5OWQ0
|
11
|
+
YjVmZWVmODMwYTQ4ZDNkMTgxM2QyZDllOTU3MGRlODI3YjFjZjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTczZjU0ZDlhNzRiZWJmMTNmOGViYjViOGIyZWQ5YTJmYWY3N2EzOTVhMmZk
|
14
|
+
YTA5ZTUzYTBmNzlkZTc4ODQzMzIxYWFkYmU4MDZkYmEzZTJiZTI1ZWFjNmE5
|
15
|
+
ODYxNjkyZTkyNTUxMzhlMGI4NjAwYTVjMTE4MTYxNTFmNDEzMjI=
|
data/lib/keynote/inline.rb
CHANGED
@@ -7,32 +7,10 @@ module Keynote
|
|
7
7
|
# body of a presenter method. You can use any template language supported by
|
8
8
|
# Rails.
|
9
9
|
#
|
10
|
-
# ## The `inline` method
|
11
|
-
#
|
12
|
-
# First, you have to declare what template languages you want to use by
|
13
|
-
# calling the {Keynote::Inline#inline} method on a presenter class:
|
14
|
-
#
|
15
|
-
# class MyPresenter < Keynote::Presenter
|
16
|
-
# presents :user, :account
|
17
|
-
# inline :haml
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# This defines a `#haml` instance method on the `MyPresenter` class.
|
21
|
-
#
|
22
|
-
# If you want to make inline templates available to all of your presenters,
|
23
|
-
# you can add an initializer like this to your application:
|
24
|
-
#
|
25
|
-
# class Keynote::Presenter
|
26
|
-
# inline :erb, :haml, :slim
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# This will add `#erb`, `#haml`, and `#slim` instance methods to all of your
|
30
|
-
# presenters.
|
31
|
-
#
|
32
10
|
# ## Basic usage
|
33
11
|
#
|
34
|
-
# After
|
35
|
-
# generate HTML by calling
|
12
|
+
# After extending the `Keynote::Inline` module in your presenter class, you
|
13
|
+
# can generate HTML by calling the `erb` method and immediately following it
|
36
14
|
# with a block of comments containing your template:
|
37
15
|
#
|
38
16
|
# def link
|
@@ -67,6 +45,31 @@ module Keynote
|
|
67
45
|
# erb x: 1, y: 2
|
68
46
|
# # <%= x + y %>
|
69
47
|
# end
|
48
|
+
#
|
49
|
+
# ## The `inline` method
|
50
|
+
#
|
51
|
+
# If you want to use template languages other than ERB, you have to define
|
52
|
+
# methods for them by calling the {Keynote::Inline#inline} method on a
|
53
|
+
# presenter class:
|
54
|
+
#
|
55
|
+
# class MyPresenter < Keynote::Presenter
|
56
|
+
# extend Keynote::Inline
|
57
|
+
# presents :user, :account
|
58
|
+
# inline :haml
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# This defines a `#haml` instance method on the `MyPresenter` class.
|
62
|
+
#
|
63
|
+
# If you want to make inline templates available to all of your presenters,
|
64
|
+
# you can add an initializer like this to your application:
|
65
|
+
#
|
66
|
+
# class Keynote::Presenter
|
67
|
+
# extend Keynote::Inline
|
68
|
+
# inline :haml, :slim
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# This will add `#erb`, `#haml`, and `#slim` instance methods to all of your
|
72
|
+
# presenters.
|
70
73
|
module Inline
|
71
74
|
# For each template format given as a parameter, add an instance method
|
72
75
|
# that can be called to render an inline template in that format. Any
|
@@ -96,6 +99,12 @@ module Keynote
|
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
102
|
+
# Extending `Keynote::Inline` automatically creates an `erb` method on the
|
103
|
+
# base class.
|
104
|
+
def self.extended(base)
|
105
|
+
base.inline :erb
|
106
|
+
end
|
107
|
+
|
99
108
|
# @private
|
100
109
|
class Renderer
|
101
110
|
def initialize(presenter, locals, caller_line, format)
|
@@ -153,7 +162,7 @@ module Keynote
|
|
153
162
|
if new_mtime != mtime
|
154
163
|
source = read_template(source_file, line)
|
155
164
|
|
156
|
-
template =
|
165
|
+
template = Template.new(source, cache_key[0],
|
157
166
|
handler_for_format(format), locals: local_names)
|
158
167
|
|
159
168
|
@cache[cache_key] = [template, new_mtime]
|
@@ -169,13 +178,13 @@ module Keynote
|
|
169
178
|
|
170
179
|
File.foreach(source_file).drop(line).each do |line|
|
171
180
|
if line =~ COMMENTED_LINE
|
172
|
-
result << $1
|
181
|
+
result << $1 << "\n"
|
173
182
|
else
|
174
183
|
break
|
175
184
|
end
|
176
185
|
end
|
177
186
|
|
178
|
-
unindent result
|
187
|
+
unindent result.chomp
|
179
188
|
end
|
180
189
|
|
181
190
|
# Borrowed from Pry, which borrowed it from Python.
|
@@ -203,5 +212,32 @@ module Keynote
|
|
203
212
|
end
|
204
213
|
end
|
205
214
|
end
|
215
|
+
|
216
|
+
# @private
|
217
|
+
class Template < ActionView::Template
|
218
|
+
# Older versions of Rails don't have this mutex, but we probably want it,
|
219
|
+
# so let's make sure it's there.
|
220
|
+
def initialize(*)
|
221
|
+
super
|
222
|
+
@compile_mutex = Mutex.new
|
223
|
+
end
|
224
|
+
|
225
|
+
# The only difference between this #compile! and the normal one is that
|
226
|
+
# we call `view.class` instead of `view.singleton_class`, so that the
|
227
|
+
# template method gets defined as an instance method on the presenter
|
228
|
+
# and therefore sticks around between presenter instances.
|
229
|
+
def compile!(view)
|
230
|
+
return if @compiled
|
231
|
+
|
232
|
+
@compile_mutex.synchronize do
|
233
|
+
return if @compiled
|
234
|
+
|
235
|
+
compile(view, view.class)
|
236
|
+
|
237
|
+
@source = nil if @virtual_path
|
238
|
+
@compiled = true
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
206
242
|
end
|
207
243
|
end
|
data/lib/keynote/railtie.rb
CHANGED
@@ -6,23 +6,8 @@ module Keynote
|
|
6
6
|
# @private
|
7
7
|
class Railtie < Rails::Railtie
|
8
8
|
config.after_initialize do |app|
|
9
|
-
|
10
|
-
|
11
|
-
else
|
12
|
-
app.config.paths.add 'app/presenters', :eager_load => true
|
13
|
-
end
|
14
|
-
|
15
|
-
if defined?(RSpec::Rails) && RSpec.respond_to?(:configure)
|
16
|
-
require 'keynote/testing/rspec'
|
17
|
-
end
|
18
|
-
|
19
|
-
if defined?(MiniTest::Rails)
|
20
|
-
require 'keynote/testing/minitest_rails'
|
21
|
-
end
|
22
|
-
|
23
|
-
if !defined?(MiniTest::Rails)
|
24
|
-
require "keynote/testing/test_unit"
|
25
|
-
end
|
9
|
+
add_presenters_to_paths(app)
|
10
|
+
load_test_integration
|
26
11
|
end
|
27
12
|
|
28
13
|
ActiveSupport.on_load(:action_view) do
|
@@ -42,5 +27,27 @@ module Keynote
|
|
42
27
|
load File.expand_path("../testing/minitest_rails.rake", __FILE__)
|
43
28
|
end
|
44
29
|
end
|
30
|
+
|
31
|
+
def self.add_presenters_to_paths(app)
|
32
|
+
if ::Rails.version.to_f >= 4
|
33
|
+
app.config.paths.add 'app/presenters'
|
34
|
+
else
|
35
|
+
app.config.paths.add 'app/presenters', :eager_load => true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.load_test_integration
|
40
|
+
if defined?(RSpec::Rails) && RSpec.respond_to?(:configure)
|
41
|
+
require 'keynote/testing/rspec'
|
42
|
+
end
|
43
|
+
|
44
|
+
if defined?(MiniTest::Rails)
|
45
|
+
require 'keynote/testing/minitest_rails'
|
46
|
+
end
|
47
|
+
|
48
|
+
if !defined?(MiniTest::Rails)
|
49
|
+
require "keynote/testing/test_unit"
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
46
53
|
end
|
data/lib/keynote/version.rb
CHANGED
data/spec/benchmarks.rb
CHANGED
data/spec/inline_spec.rb
CHANGED
@@ -16,7 +16,7 @@ module Keynote
|
|
16
16
|
|
17
17
|
class InlineUser < Keynote::Presenter
|
18
18
|
extend Keynote::Inline
|
19
|
-
inline :
|
19
|
+
inline :slim, :haml
|
20
20
|
|
21
21
|
def simple_template
|
22
22
|
erb
|
@@ -53,8 +53,9 @@ module Keynote
|
|
53
53
|
|
54
54
|
def fix_indentation
|
55
55
|
slim
|
56
|
-
#
|
57
|
-
#
|
56
|
+
# .indented_slightly
|
57
|
+
# - (2..4).each do |i|
|
58
|
+
# ' #{i} times
|
58
59
|
end
|
59
60
|
|
60
61
|
def erb_escaping
|
@@ -100,7 +101,7 @@ module Keynote
|
|
100
101
|
end
|
101
102
|
|
102
103
|
it "should be able to call other methods from the same object" do
|
103
|
-
presenter.method_calls.strip.squeeze(" ").must_equal "Local H
|
104
|
+
presenter.method_calls.strip.squeeze(" ").must_equal "Local H\nLocal H"
|
104
105
|
end
|
105
106
|
|
106
107
|
it "should handle errors relatively gracefully" do
|
@@ -116,7 +117,7 @@ module Keynote
|
|
116
117
|
|
117
118
|
it "should remove leading indentation" do
|
118
119
|
presenter.fix_indentation.must_equal \
|
119
|
-
"<div class=\"indented_slightly\">
|
120
|
+
"<div class=\"indented_slightly\">2 times 3 times 4 times </div>"
|
120
121
|
end
|
121
122
|
|
122
123
|
it "should escape HTML by default" do
|