middleman-core 4.5.1 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +0 -2
  3. data/.yardopts +1 -2
  4. data/Rakefile +1 -1
  5. data/features/builder.feature +4 -4
  6. data/features/content_type.feature +1 -1
  7. data/features/data.feature +5 -0
  8. data/features/front-matter.feature +21 -0
  9. data/features/minify_javascript.feature +38 -39
  10. data/features/preview_changes.feature +11 -0
  11. data/features/sass_in_slim.feature +2 -2
  12. data/features/support/env.rb +8 -0
  13. data/fixtures/data-with-aliases-app/config.rb +3 -0
  14. data/fixtures/data-with-aliases-app/data/pages.yml +9 -0
  15. data/fixtures/data-with-aliases-app/source/index.html.erb +1 -0
  16. data/fixtures/data-with-aliases-app/source/layout.erb +5 -0
  17. data/fixtures/generator-test/config.rb +1 -14
  18. data/fixtures/sinatra-app/config.rb +2 -0
  19. data/lib/middleman-core/application.rb +0 -13
  20. data/lib/middleman-core/builder.rb +3 -3
  21. data/lib/middleman-core/contracts.rb +0 -1
  22. data/lib/middleman-core/core_extensions/collections/lazy_root.rb +1 -1
  23. data/lib/middleman-core/core_extensions/collections/lazy_step.rb +1 -1
  24. data/lib/middleman-core/extensions/minify_javascript.rb +1 -1
  25. data/lib/middleman-core/file_renderer.rb +1 -7
  26. data/lib/middleman-core/preview_server/server_hostname.rb +0 -2
  27. data/lib/middleman-core/preview_server.rb +3 -2
  28. data/lib/middleman-core/rack.rb +6 -6
  29. data/lib/middleman-core/renderers/coffee_script.rb +2 -6
  30. data/lib/middleman-core/renderers/erb.rb +15 -3
  31. data/lib/middleman-core/renderers/haml.rb +1 -3
  32. data/lib/middleman-core/renderers/kramdown.rb +7 -11
  33. data/lib/middleman-core/renderers/less.rb +10 -26
  34. data/lib/middleman-core/renderers/liquid.rb +1 -1
  35. data/lib/middleman-core/renderers/redcarpet.rb +4 -14
  36. data/lib/middleman-core/renderers/sass.rb +3 -10
  37. data/lib/middleman-core/renderers/sass_functions.rb +2 -2
  38. data/lib/middleman-core/renderers/slim.rb +9 -1
  39. data/lib/middleman-core/sources/source_watcher.rb +1 -1
  40. data/lib/middleman-core/step_definitions/commandline_steps.rb +14 -14
  41. data/lib/middleman-core/step_definitions.rb +3 -0
  42. data/lib/middleman-core/template_renderer.rb +2 -2
  43. data/lib/middleman-core/util/data.rb +4 -5
  44. data/lib/middleman-core/util/paths.rb +2 -1
  45. data/lib/middleman-core/util.rb +6 -0
  46. data/lib/middleman-core/version.rb +1 -1
  47. data/lib/middleman-core.rb +0 -2
  48. data/middleman-core.gemspec +16 -15
  49. data/spec/spec_helper.rb +2 -2
  50. metadata +1176 -62
  51. data/.gemtest +0 -0
  52. data/.rspec +0 -1
  53. data/cucumber.yml +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d17dfddbf442da6e1bbf5be0c19bab7de0b71357264de5bb3a421ef932ef0912
4
- data.tar.gz: 6b20f531c4b57ecf0f35d7573708e8714e79c4c9b82806235243a9ae1b192029
3
+ metadata.gz: 4f75b57d4f7b5046290d41e0748282ab8fa02a2b230be9fb5045242432f2a72d
4
+ data.tar.gz: 4aba8ff90a5e723281990b3a1a7341509c1aa8891d231ecc3fe3ad39de29c7e9
5
5
  SHA512:
6
- metadata.gz: a345b95ff2e21b871351e163ced5c4148459b4cd24e34e3686b3e4c29d7070b3170e3ad92b0c108a532c873637eba6272f4fcbfea3091e7abf2c25eda2fbd6d0
7
- data.tar.gz: 282d36c604c623fd5d0856bb8b559a52bbb381bd09f1df1d68cfa37676826a10b7a6f6d7f674b4c783b93d0cb4cff0b1660a6db55f0b116a1a5cf9dc1a330304
6
+ metadata.gz: 3e63cf33f58076d4b2d8ebcaf7803157236a86443e273ea0400d93aa6a8456c7e641ca0552a6ed9197f3494ba045dd22c8fafef293f6aad5273d1bc9cc8cc5b6
7
+ data.tar.gz: d2012044ebe3eaf1aaba82208b945d03fc18bc9830373cc5603242bc90eef9183c852ad0c7e2cf2ad6e047b7eace0c14228ca77e152c32579d34f9e5d4cfe393
data/.simplecov CHANGED
@@ -2,6 +2,4 @@ SimpleCov.configure do
2
2
  add_filter '/fixtures/'
3
3
  add_filter '/features/'
4
4
  add_filter '/spec/'
5
- add_filter '/step_definitions/'
6
- add_filter '/lib/vendored-middleman-deps/'
7
5
  end
data/.yardopts CHANGED
@@ -1,6 +1,5 @@
1
1
  lib/**/*.rb
2
- --exclude lib/vendored-middleman-deps/
3
2
  --exclude lib/middleman-core/step_definitions
4
3
  --no-private
5
4
  --hide-void-return
6
- --markup=markdown
5
+ --markup=markdown
data/Rakefile CHANGED
@@ -1,3 +1,3 @@
1
1
  RAKE_ROOT = __FILE__.freeze
2
2
  GEM_NAME = ENV['NAME'] || 'middleman-core'
3
- require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
3
+ require File.expand_path("#{File.dirname(__FILE__)}/../gem_rake_helper")
@@ -55,7 +55,7 @@ Feature: Builder
55
55
  Scenario: Builded text file(ex: html, css, xml, txt)'s permission is 0644
56
56
  Given a successfully built app at "large-build-app"
57
57
  When I cd to "build"
58
- Then the mode of filesystem object "index.html" should match "0644"
59
- And the mode of filesystem object "stylesheets/static.css" should match "0644"
60
- And the mode of filesystem object "feed.xml" should match "0644"
61
- And the mode of filesystem object ".htaccess" should match "0644"
58
+ Then the file named "index.html" should have permissions "0644"
59
+ And the file named "stylesheets/static.css" should have permissions "0644"
60
+ And the file named "feed.xml" should have permissions "0644"
61
+ And the file named ".htaccess" should have permissions "0644"
@@ -7,7 +7,7 @@ Feature: Setting the right content type for files
7
7
  When I go to "/images/blank.gif"
8
8
  Then the content type should be "image/gif"
9
9
  When I go to "/javascripts/app.js"
10
- Then the content type should be "application/javascript"
10
+ Then the content type should be "text/javascript"
11
11
  When I go to "/stylesheets/site.css"
12
12
  Then the content type should be "text/css"
13
13
  When I go to "/README"
@@ -83,6 +83,11 @@ Feature: Local Data API
83
83
  Then I should see "title2:More"
84
84
  Then I should see "title3:Stuff"
85
85
 
86
+ Scenario: Using data with aliases
87
+ Given the Server is running at "data-with-aliases-app"
88
+ When I go to "/test1.html"
89
+ Then I should see "Welcome"
90
+
86
91
  Scenario: Using data postscript
87
92
  Given the Server is running at "nested-data-app"
88
93
  When I go to "/extracontent.html"
@@ -80,6 +80,27 @@ Feature: YAML Front Matter
80
80
  When I go to "/front-matter-change.html"
81
81
  Then I should see "Hello World"
82
82
 
83
+ Scenario: A template should handle YAML with types
84
+ Given the Server is running at "frontmatter-app"
85
+ And the file "source/front-matter-types.html.erb" has the contents
86
+ """
87
+ ---
88
+ date_matter: 2020-01-01
89
+ time_matter: 2020-12-31 13:14:15 +0000
90
+ symbol_matter: :a_symbol
91
+ regexp_matter: !ruby/regexp /a|b/
92
+ ---
93
+ Date: <%= current_page.data.date_matter.strftime('%d %m %Y') %>
94
+ Time: <%= current_page.data.time_matter.strftime('%d %m %Y %H::%M::%S %z') %>
95
+ Symbol: <%= current_page.data.symbol_matter.is_a? Symbol %>
96
+ Regexp: <%= "za" =~ current_page.data.regexp_matter %>
97
+ """
98
+ When I go to "/front-matter-types.html"
99
+ Then I should see "Date: 01 01 2020"
100
+ Then I should see "Time: 31 12 2020 13::14::15 +0000"
101
+ Then I should see "Symbol: true"
102
+ Then I should see "Regexp: 1"
103
+
83
104
  Scenario: Rendering raw (template-less) (toml)
84
105
  Given the Server is running at "frontmatter-app"
85
106
  When I go to "/raw-front-matter-toml.html"
@@ -19,23 +19,23 @@ Feature: Minify Javascript
19
19
  })();
20
20
  </script>
21
21
  <script>
22
- ;(function() {
23
- this;
24
- should();
25
- too();
26
- })();
22
+ ;(function() {
23
+ this;
24
+ should();
25
+ too();
26
+ })();
27
27
  </script>
28
28
  <script type='text/javascript'>
29
- //<!--
30
- ;(function() {
31
- one;
32
- line();
33
- here();
34
- })();
35
- //-->
29
+ //<!--
30
+ ;(function() {
31
+ one;
32
+ line();
33
+ here();
34
+ })();
35
+ //-->
36
36
  </script>
37
37
  <script type='text/html'>
38
- I'm a jQuery {{template}}.
38
+ I'm a jQuery {{template}}.
39
39
  </script>
40
40
  """
41
41
 
@@ -66,23 +66,23 @@ Feature: Minify Javascript
66
66
  })();
67
67
  </script>
68
68
  <script>
69
- ;(function() {
70
- this;
71
- should();
72
- too();
73
- })();
69
+ ;(function() {
70
+ this;
71
+ should();
72
+ too();
73
+ })();
74
74
  </script>
75
75
  <script type='text/javascript'>
76
- //<!--
77
- ;(function() {
78
- one;
79
- line();
80
- here();
81
- })();
82
- //-->
76
+ //<!--
77
+ ;(function() {
78
+ one;
79
+ line();
80
+ here();
81
+ })();
82
+ //-->
83
83
  </script>
84
84
  <script type='text/html'>
85
- I'm a jQuery {{template}}.
85
+ I'm a jQuery {{template}}.
86
86
  </script>
87
87
  """
88
88
 
@@ -108,15 +108,15 @@ Feature: Minify Javascript
108
108
  Hello
109
109
  </script>
110
110
  <script>
111
- Hello
111
+ Hello
112
112
  </script>
113
113
  <script type='text/javascript'>
114
- //<!--
114
+ //<!--
115
115
  Hello
116
- //-->
116
+ //-->
117
117
  </script>
118
118
  <script type='text/html'>
119
- I'm a jQuery {{template}}.
119
+ I'm a jQuery {{template}}.
120
120
  </script>
121
121
  """
122
122
 
@@ -131,18 +131,18 @@ Feature: Minify Javascript
131
131
  Then I should see:
132
132
  """
133
133
  <script>
134
- !function(){should(),all.be(),on={one:line}}();
134
+ should(),all.be(),on={one:line};
135
135
  </script>
136
136
  <script>
137
- !function(){should(),too()}();
137
+ should(),too();
138
138
  </script>
139
139
  <script type='text/javascript'>
140
- //<!--
141
- !function(){one,line(),here()}();
142
- //-->
140
+ //<!--
141
+ one,line(),here();
142
+ //-->
143
143
  </script>
144
144
  <script type='text/html'>
145
- I'm a jQuery {{template}}.
145
+ I'm a jQuery {{template}}.
146
146
  </script>
147
147
  """
148
148
 
@@ -159,11 +159,11 @@ Feature: Minify Javascript
159
159
  <?='Hello'?>
160
160
 
161
161
  <script>
162
- !function(){should(),all.be(),on={one:line}}();
162
+ should(),all.be(),on={one:line};
163
163
  </script>
164
164
  <script type='text/javascript'>
165
165
  //<!--
166
- !function(){one,line(),here()}();
166
+ one,line(),here();
167
167
  //-->
168
168
  </script>
169
169
  <script type='text/html'>
@@ -263,4 +263,3 @@ Feature: Minify Javascript
263
263
  And the Server is running at "passthrough-app"
264
264
  When I go to "/javascripts/coffee_test.js"
265
265
  Then I should see "11" lines
266
-
@@ -27,3 +27,14 @@ Feature: Preview Changes
27
27
  And the file "source/a-page.html.erb" is removed
28
28
  When I go to "/a-page.html"
29
29
  Then I should see "File Not Found"
30
+
31
+ Scenario: A template with apostrophe is reloaded during preview
32
+ Given the Server is running at "preview-app"
33
+ And the file "source/a-page.html.erb" has the contents
34
+ """
35
+ Matz's Ruby Interpreter
36
+ """
37
+ When I go to "/a-page.html"
38
+ Then I should see "Matz's Ruby Interpreter"
39
+ When I go to "/a-page.html"
40
+ Then I should see "Matz's Ruby Interpreter"
@@ -15,7 +15,7 @@ Feature: Sass/SCSS support in Slim
15
15
  """
16
16
  Given the Server is running at "sass-in-slim-app"
17
17
  When I go to "/sass_filter/"
18
- Then I should see "text/css"
18
+ Then I should see "<style>"
19
19
  Then I should see ".sass"
20
20
  Then I should see "margin:0"
21
21
 
@@ -35,6 +35,6 @@ Feature: Sass/SCSS support in Slim
35
35
  """
36
36
  Given the Server is running at "sass-in-slim-app"
37
37
  When I go to "/scss_filter/"
38
- Then I should see "text/css"
38
+ Then I should see "<style>"
39
39
  Then I should see ".scss"
40
40
  Then I should see "margin:0"
@@ -7,6 +7,14 @@ SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/../..'))
7
7
 
8
8
  SimpleCov.start
9
9
 
10
+ require "rspec"
11
+
12
+ RSpec.configure do |config|
13
+ config.expect_with :rspec do |expectations|
14
+ expectations.max_formatted_output_length = nil
15
+ end
16
+ end
17
+
10
18
  PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
11
19
  require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-core')
12
20
  require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-core', 'step_definitions')
@@ -0,0 +1,3 @@
1
+ data.pages.each do |p|
2
+ proxy p.from, p.to, locals: { content: p.content }
3
+ end
@@ -0,0 +1,9 @@
1
+ -
2
+ from: "/test1.html"
3
+ to: "/index.html"
4
+ content: &greeting 'Welcome'
5
+
6
+ -
7
+ from: "/test2.html"
8
+ to: "/index.html"
9
+ content: *greeting
@@ -0,0 +1 @@
1
+ <p><%= content %></p>
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ <%= yield %>
4
+ </body>
5
+ </html>
@@ -1,16 +1,3 @@
1
- ###
2
- # Compass
3
- ###
4
-
5
- # Susy grids in Compass
6
- # First: gem install compass-susy-plugin
7
- # require 'susy'
8
-
9
- # Change Compass configuration
10
- # compass_config do |config|
11
- # config.output_style = :compact
12
- # end
13
-
14
1
  ###
15
2
  # Page options, layouts, aliases and proxies
16
3
  ###
@@ -53,7 +40,7 @@
53
40
 
54
41
  # Production configuration
55
42
  configure :production do
56
- # For example, change the Compass output style for deployment
43
+ # Minify CSS
57
44
  # activate :minify_css
58
45
 
59
46
  # Minify Javascript
@@ -1,6 +1,8 @@
1
1
  require "sinatra"
2
2
 
3
3
  class MySinatra < Sinatra::Base
4
+ set :host_authorization, { permitted_hosts: "www.example.com" }
5
+
4
6
  get "/" do
5
7
  "Hello World (Sinatra)"
6
8
  end
@@ -300,8 +300,6 @@ module Middleman
300
300
  Encoding.default_external = config[:encoding]
301
301
  end
302
302
 
303
- prune_tilt_templates!
304
-
305
303
  # After extensions have worked after_config
306
304
  execute_callbacks(:after_configuration)
307
305
 
@@ -343,17 +341,6 @@ module Middleman
343
341
  config_context.instance_eval File.read(env_config), env_config, 1
344
342
  end
345
343
 
346
- # Clean up missing Tilt exts
347
- def prune_tilt_templates!
348
- ::Tilt.default_mapping.lazy_map.each_key do |key|
349
- begin
350
- ::Tilt[".#{key}"]
351
- rescue LoadError, NameError
352
- ::Tilt.default_mapping.lazy_map.delete(key)
353
- end
354
- end
355
- end
356
-
357
344
  # Whether we're in a specific mode
358
345
  # @param [Symbol] key
359
346
  # @return [Boolean]
@@ -87,7 +87,7 @@ module Middleman
87
87
  !@has_error
88
88
  end
89
89
 
90
- # Pre-request CSS to give Compass a chance to build sprites
90
+ # Pre-request CSS to give Sass a chance to build sprites
91
91
  # @return [Array<Resource>] List of css resources that were output.
92
92
  Contract ResourceList
93
93
  def prerender_css
@@ -99,9 +99,9 @@ module Middleman
99
99
  end
100
100
 
101
101
  ::Middleman::Util.instrument 'builder.prerender.check-files' do
102
- # Double-check for compass sprites
102
+ # Double-check for Sass sprites
103
103
  unless @app.files.find_new_files!.empty?
104
- logger.debug '== Checking for Compass sprites'
104
+ logger.debug '== Checking for Sass sprites'
105
105
  @app.sitemap.ensure_resource_list_updated!
106
106
  end
107
107
  end
@@ -27,7 +27,6 @@ else
27
27
  base.extend self
28
28
  end
29
29
 
30
- # rubocop:disable MethodName
31
30
  def Contract(*); end
32
31
 
33
32
  class Callable
@@ -3,7 +3,7 @@ require 'middleman-core/core_extensions/collections/lazy_step'
3
3
  module Middleman
4
4
  module CoreExtensions
5
5
  module Collections
6
- class LazyCollectorRoot < BasicObject
6
+ class LazyCollectorRoot
7
7
  def initialize(parent)
8
8
  @data = nil
9
9
  @parent = parent
@@ -1,7 +1,7 @@
1
1
  module Middleman
2
2
  module CoreExtensions
3
3
  module Collections
4
- class LazyCollectorStep < BasicObject
4
+ class LazyCollectorStep
5
5
  DELEGATE = [:hash, :eql?].freeze
6
6
 
7
7
  def initialize(name, args, block, parent=nil)
@@ -10,7 +10,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
10
10
  require 'uglifier'
11
11
  ::Uglifier.new
12
12
  }, 'Set the JS compressor to use.'
13
- option :content_types, %w(application/javascript), 'Content types of resources that contain JS'
13
+ option :content_types, %w(text/javascript), 'Content types of resources that contain JS'
14
14
  option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline JS'
15
15
 
16
16
  def ready
@@ -67,15 +67,9 @@ module Middleman
67
67
  end
68
68
 
69
69
  # Read compiled template from disk or cache
70
- template = ::Tilt.new(path, 1, options) { body }
71
- # template = cache.fetch(:compiled_template, extension, options, body) do
72
- # ::Tilt.new(path, 1, options) { body }
73
- # end
70
+ template = ::Tilt.new(path, 1, options) { body.dup }
74
71
 
75
72
  # Render using Tilt
76
- # content = ::Middleman::Util.instrument 'render.tilt', path: path do
77
- # template.render(context, locs, &block)
78
- # end
79
73
  content = template.render(context, locs, &block)
80
74
 
81
75
  # Allow hooks to manipulate the result after render
@@ -19,9 +19,7 @@ module Middleman
19
19
  end
20
20
 
21
21
  def self.match?(name)
22
- # rubocop:disable Style/CaseEquality
23
22
  name != 'localhost' && /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?\.?$/ === name
24
- # rubocop:enable Style/CaseEquality
25
23
  end
26
24
 
27
25
  alias to_browser to_s
@@ -8,7 +8,6 @@ require 'middleman-core/preview_server/server_information'
8
8
  require 'middleman-core/preview_server/server_url'
9
9
  require 'middleman-core/preview_server/server_information_callback_proxy'
10
10
 
11
- # rubocop:disable GlobalVars
12
11
  module Middleman
13
12
  class PreviewServer
14
13
  class << self
@@ -315,7 +314,9 @@ module Middleman
315
314
  @webrick ||= setup_webrick(@options[:debug] || false)
316
315
 
317
316
  rack_app = ::Middleman::Rack.new(@app).to_app
318
- @webrick.mount '/', ::Rack::Handler::WEBrick, rack_app
317
+
318
+ require "rackup/handler/webrick"
319
+ @webrick.mount '/', ::Rackup::Handler::WEBrick, rack_app
319
320
  end
320
321
 
321
322
  # Detach the current Middleman::Application instance
@@ -1,5 +1,5 @@
1
1
  require 'rack'
2
- require 'rack/file'
2
+ require 'rack/files'
3
3
  require 'rack/lint'
4
4
  require 'rack/head'
5
5
  require 'rack/utils'
@@ -106,7 +106,7 @@ module Middleman
106
106
  # If this path is a binary file, send it immediately
107
107
  return send_file(resource, env) if resource.binary?
108
108
 
109
- res['Content-Type'] = resource.content_type || 'text/plain'
109
+ res['content-type'] = resource.content_type || 'text/plain'
110
110
 
111
111
  begin
112
112
  # Write out the contents of the page
@@ -134,7 +134,7 @@ module Middleman
134
134
 
135
135
  # Immediately send static file
136
136
  def send_file(resource, env)
137
- file = ::Rack::File.new nil
137
+ file = ::Rack::Files.new nil
138
138
  path = resource.file_descriptor[:full_path]
139
139
  if !file.respond_to?(:path=)
140
140
  request = ::Rack::Request.new(env)
@@ -144,11 +144,11 @@ module Middleman
144
144
  response = file.serving(env)
145
145
  end
146
146
  status = response[0]
147
- response[1]['Content-Encoding'] = 'gzip' if %w(.svgz .gz).include?(resource.ext)
148
- # Do not set Content-Type if status is 1xx, 204, 205 or 304, otherwise
147
+ response[1]['content-encoding'] = 'gzip' if %w(.svgz .gz).include?(resource.ext)
148
+ # Do not set content-type if status is 1xx, 204, 205 or 304, otherwise
149
149
  # Rack will throw an error (500)
150
150
  if !(100..199).cover?(status) && ![204, 205, 304].include?(status)
151
- response[1]['Content-Type'] = resource.content_type || 'application/octet-stream'
151
+ response[1]['content-type'] = resource.content_type || 'application/octet-stream'
152
152
  end
153
153
  halt response
154
154
  end
@@ -21,14 +21,10 @@ module Middleman
21
21
  # Make the current Middleman app accessible to the template
22
22
  cattr_accessor :middleman_app
23
23
 
24
- # Add exception messaging
25
- # @param [Class] context
26
- # @param [Hash] locals
27
- # @return [String]
28
- def evaluate(context, locals, &block)
24
+ def prepare
29
25
  return super unless middleman_app.server?
30
26
 
31
- begin
27
+ @output = begin
32
28
  super
33
29
  rescue ::ExecJS::RuntimeError => e
34
30
  e.to_s
@@ -6,14 +6,26 @@ module Middleman
6
6
  ::Tilt.prefer(Template, :erb)
7
7
  end
8
8
 
9
- class Template < ::Tilt::ErubisTemplate
9
+ class Template < ::Tilt::ErubiTemplate
10
+ def initialize(*args, &block)
11
+ super
12
+
13
+ @context = @options[:context]
14
+ end
15
+
10
16
  ##
11
- # In preamble we need a flag `__in_erb_template` and SafeBuffer for padrino apps.
17
+ # In preamble we need a flag `__in_erb_template` for padrino apps.
12
18
  #
13
19
  def precompiled_preamble(locals)
14
20
  original = super
15
21
  "__in_erb_template = true\n" << original
16
- # .rpartition("\n").first << "#{@outvar} = _buf = ActiveSupport::SafeBuffer.new\n"
22
+ end
23
+
24
+ ##
25
+ # Force the template the use the configured encoding.
26
+ #
27
+ def precompiled_template(locals)
28
+ super.dup.force_encoding(@context.app.config[:encoding])
17
29
  end
18
30
  end
19
31
  end
@@ -23,7 +23,7 @@ module Middleman
23
23
  def initialize(*args, &block)
24
24
  super
25
25
 
26
- @context = @options[:context] if @options.key?(:context)
26
+ @context = @options[:context]
27
27
  end
28
28
 
29
29
  def prepare; end
@@ -62,7 +62,6 @@ module Middleman
62
62
  ::Haml::TempleEngine.define_options context: nil
63
63
  end
64
64
 
65
- # rubocop:disable NestedMethodDefinition
66
65
  [::Haml::Filters::Sass, ::Haml::Filters::Scss, ::Haml::Filters::Markdown].each do |f|
67
66
  f.class_exec do
68
67
  if respond_to?(:template_class) # Haml 5 and older
@@ -93,7 +92,6 @@ module Middleman
93
92
  end
94
93
  end
95
94
  end
96
- # rubocop:enable NestedMethodDefinition
97
95
 
98
96
  ::Tilt.prefer(::Middleman::Renderers::HamlTemplate, :haml)
99
97
 
@@ -4,20 +4,16 @@ module Middleman
4
4
  module Renderers
5
5
  # Our own Kramdown Tilt template that simply uses our custom renderer.
6
6
  class KramdownTemplate < ::Tilt::KramdownTemplate
7
- def initialize(*args, &block)
8
- super
7
+ private
9
8
 
10
- @context = @options[:context] if @options.key?(:context)
11
- end
12
-
13
- def evaluate(context, *)
9
+ def _prepare_output
10
+ @context = @options[:context]
14
11
  MiddlemanKramdownHTML.scope = @context || context
15
12
 
16
- @output ||= begin
17
- output, warnings = MiddlemanKramdownHTML.convert(@engine.root, @engine.options)
18
- @engine.warnings.concat(warnings)
19
- output
20
- end
13
+ @engine = Kramdown::Document.new(data, options)
14
+ output, warnings = MiddlemanKramdownHTML.convert(@engine.root, @engine.options)
15
+ @engine.warnings.concat(warnings)
16
+ output
21
17
  end
22
18
  end
23
19