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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGI0NGI2NzM1NTYwNDk0YTEyNmIxMDNmMTQxMTBmZDFiNGQ1ZTU4ZA==
4
+ MzFlYTA4N2M3ZDE3NjA0MGNlZTgxYjI2YTJiZjAyNWYyMTMwODUyMQ==
5
5
  data.tar.gz: !binary |-
6
- MzhjMjY0ZDBlNmY2NGYxNTE5ODI4YTBhZGMwYmYxZDUzNzJmZTVkNA==
6
+ MzgwNTJmNzhiMjZjOTBmMTkxZDg0MWE0NzVkZDE0NzhmNDA3NjAwNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZGY2ZmRiYzZmNmQ2NDY0NzdlN2QwMzczY2IyYTAzN2Q5NDkxYmJhYjk1ZjZh
10
- MmZkNWU5NDFkNjE4NTFkYzc0MDliZGVmZWFjZmVhMTJmYjhhMjgwMjhhYWYx
11
- ZTZjZTI1NzAwOGJjYmY1YWNhM2E4ZThkOWNiYzFkMjdiOGI0MjI=
9
+ YmIzNThlN2FhNWM0OGZjNTdjZmQ5MTJjYWZmMTAzZjAwYjBjYzA3MWM4Nzdh
10
+ NDJhZDg5NjgxNjY2NTI0MTNjMDc0ZjdkYzNlYjFhNmVlMTNmNTYwZjM5OWQ0
11
+ YjVmZWVmODMwYTQ4ZDNkMTgxM2QyZDllOTU3MGRlODI3YjFjZjU=
12
12
  data.tar.gz: !binary |-
13
- MjQ5NzdmYjAxYmUxNzA1NTE4M2E1YTc2Y2Y2NDQ0NDNiNTA4ZDA4MTM4M2U2
14
- MjBlOWI1OTVhNWU1ZDU2YzY1ODA4ZjYzMTZiOWE3NGI5M2Y0NWFiODUzOTgy
15
- OWY0ZDEwMGVlMWVlY2ViMjI0NWZhYjMzN2Q1N2NmYjYyNGE3ZTc=
13
+ OTczZjU0ZDlhNzRiZWJmMTNmOGViYjViOGIyZWQ5YTJmYWY3N2EzOTVhMmZk
14
+ YTA5ZTUzYTBmNzlkZTc4ODQzMzIxYWFkYmU4MDZkYmEzZTJiZTI1ZWFjNmE5
15
+ ODYxNjkyZTkyNTUxMzhlMGI4NjAwYTVjMTE4MTYxNTFmNDEzMjI=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/rfitz/src/keynote
3
3
  specs:
4
- keynote (0.2.0pre1)
4
+ keynote (0.2.0pre2)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/rfitz/src/keynote
3
3
  specs:
4
- keynote (0.2.0pre1)
4
+ keynote (0.2.0pre2)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/rfitz/src/keynote
3
3
  specs:
4
- keynote (0.2.0pre1)
4
+ keynote (0.2.0pre2)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/rfitz/src/keynote
3
3
  specs:
4
- keynote (0.2.0pre1)
4
+ keynote (0.2.0pre2)
5
5
  rails (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -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 defining one or more instance methods by calling `inline`, you can
35
- # generate HTML by calling one of those methods and immediately following it
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 = ActionView::Template.new(source, cache_key[0],
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
@@ -6,23 +6,8 @@ module Keynote
6
6
  # @private
7
7
  class Railtie < Rails::Railtie
8
8
  config.after_initialize do |app|
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
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Keynote
4
4
  # @private
5
- VERSION = "0.2.0pre2"
5
+ VERSION = "0.2.0pre3"
6
6
  end
@@ -8,6 +8,7 @@ require "keynote"
8
8
  require "benchmark"
9
9
 
10
10
  class MyPresenter < Keynote::Presenter
11
+ extend Keynote::Inline
11
12
  inline :erb
12
13
 
13
14
  def my_string
@@ -16,7 +16,7 @@ module Keynote
16
16
 
17
17
  class InlineUser < Keynote::Presenter
18
18
  extend Keynote::Inline
19
- inline :erb, :slim, :haml
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
- # div.indented_slightly
57
- # = "hello"
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 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\">hello</div>"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keynote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0pre2
4
+ version: 0.2.0pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Fitzgerald