middleman-core 3.1.0.rc.3 → 3.1.0.rc.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d409fa4b4685ed3179880f7ec5f6b3d738b02cb5
4
- data.tar.gz: 85297e96e43c14c1cdc4f08acb9c909f5eef6e04
3
+ metadata.gz: 25781ccd8de535b9b6789b101762fa1dc753ae58
4
+ data.tar.gz: 0be523cddc28bbb739c6b2afb37221fe9afd53b1
5
5
  SHA512:
6
- metadata.gz: eb1fc2f29f119b5972c274f85bad7601e981aeba564a33ea0ec97fe3be68e84da70e5db0e08e6120f73e4c9c4f740b2f38c78aeb87b971c0cfa3e715a66de476
7
- data.tar.gz: d5487e80ecd0b193602ab72ea0de5764685998a1838c8bfca0f3fd1a320c21e542dd568abd660085aa5acc33d32fd74f50d61f16f17edc272fd878f20f1f88bc
6
+ metadata.gz: 9f2a22f4e27d44ee57fb3ad1a690736dd2bb626073e1ce69462bf687fa9048afdaac3ff571f28114e60c6ed307e7d355d244ad94e81cbc78104f7daccc76dfdb
7
+ data.tar.gz: bcffd4386d2100d62175e025a2bc236d90865e45666a46cdb856a60501f5a9f25779aee651ff7803d78befe3ac5f5aab5f2935c38fdc2425195395031dbc44a7
@@ -1,5 +1,20 @@
1
1
  Feature: link_to helper
2
2
 
3
+ Scenario: link_to works with blocks (erb)
4
+ Given the Server is running at "link-to-app"
5
+ When I go to "/link_to_erb.html"
6
+ Then I should see "erb <s>with html tags</s>"
7
+
8
+ Scenario: link_to works with blocks (slim)
9
+ Given the Server is running at "link-to-app"
10
+ When I go to "/link_to_slim.html"
11
+ Then I should see "<s>slim with html tags</s>"
12
+
13
+ Scenario: link_to works with blocks (haml)
14
+ Given the Server is running at "link-to-app"
15
+ When I go to "/link_to_haml.html"
16
+ Then I should see "<s>haml with html tags</s>"
17
+
3
18
  Scenario: link_to produces relative links
4
19
  Given a fixture app "indexable-app"
5
20
  And an empty file named "config.rb"
@@ -10,4 +10,14 @@ Feature: Markdown support
10
10
  Scenario: Markdown extensions (Maruku)
11
11
  Given the Server is running at "markdown-app"
12
12
  When I go to "/smarty_pants.html"
13
- Then I should see "“Hello”"
13
+ Then I should see "“Hello”"
14
+
15
+ Scenario: Links with block syntax in ERB layout (erb)
16
+ Given the Server is running at "more-markdown-app"
17
+ When I go to "/with_layout_erb.html"
18
+ Then I should see '<a href="layout_block_link.html">'
19
+
20
+ Scenario: Links with block syntax in ERB layout and markdown
21
+ Given the Server is running at "more-markdown-app"
22
+ When I go to "/with_layout.html"
23
+ Then I should see '<a href="layout_block_link.html">'
@@ -5,4 +5,63 @@ Feature: Support Rack apps mounted using map
5
5
  When I go to "/"
6
6
  Then I should see "Hello World (Middleman)"
7
7
  When I go to "/sinatra/"
8
- Then I should see "Hello World (Sinatra)"
8
+ Then I should see "Hello World (Sinatra)"
9
+
10
+ Scenario: Built Mounted Rack App at /sinatra
11
+ Given a successfully built app at "sinatra-app"
12
+ When I cd to "build"
13
+ Then the following files should exist:
14
+ | index.html |
15
+ Then the following files should not exist:
16
+ | sinatra/index.html |
17
+ | sinatra/index2.html |
18
+
19
+ Scenario: Static Ruby Endpoints
20
+ Given a fixture app "sinatra-app"
21
+ And a file named "config.rb" with:
22
+ """
23
+ endpoint "hello.html" do
24
+ "world"
25
+ end
26
+ """
27
+ And the Server is running at "sinatra-app"
28
+ When I go to "/hello.html"
29
+ Then I should see "world"
30
+
31
+ Scenario: Built Mounted Rack App at /sinatra (including rack endpoints)
32
+ Given a fixture app "sinatra-app"
33
+ And a file named "config.rb" with:
34
+ """
35
+ require "sinatra"
36
+
37
+ class MySinatra < Sinatra::Base
38
+ get "/" do
39
+ "Hello World (Sinatra)"
40
+ end
41
+ get "/derp.html" do
42
+ "De doo"
43
+ end
44
+ end
45
+
46
+ map "/sinatra" do
47
+ run MySinatra
48
+ end
49
+
50
+ configure :build do
51
+ endpoint "sinatra/index2.html", :path => "/sinatra/"
52
+ end
53
+
54
+ endpoint "dedoo.html", :path => "/sinatra/derp.html"
55
+
56
+ endpoint "hello.html" do
57
+ "world"
58
+ end
59
+ """
60
+ And a successfully built app at "sinatra-app"
61
+ When I cd to "build"
62
+ Then the following files should exist:
63
+ | index.html |
64
+ | sinatra/index2.html |
65
+ | dedoo.html |
66
+ And the file "sinatra/index2.html" should contain 'Hello World (Sinatra)'
67
+ And the file "dedoo.html" should contain 'De doo'
File without changes
@@ -0,0 +1,3 @@
1
+ <% link_to "/" do %>
2
+ erb <s>with html tags</s>
3
+ <% end %>
@@ -0,0 +1,2 @@
1
+ - link_to "/" do
2
+ %s haml with html tags
@@ -0,0 +1,2 @@
1
+ - link_to "/" do
2
+ s slim with html tags
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <title>My Sample Site</title>
4
+ <!-- Comment in layout -->
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+
9
+ <% link_to "layout_block_link.html" do %>
10
+ Block link text
11
+ <% end %>
12
+ </body>
13
+ </html>
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: layout
3
+ ---
4
+ Hello World
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: layout
3
+ ---
4
+ Hello World
@@ -4,6 +4,9 @@ class MySinatra < Sinatra::Base
4
4
  get "/" do
5
5
  "Hello World (Sinatra)"
6
6
  end
7
+ get "/derp.html" do
8
+ "De doo"
9
+ end
7
10
  end
8
11
 
9
12
  map "/sinatra" do
@@ -135,7 +135,7 @@ module Middleman::Cli
135
135
  FileUtils.cp(resource.source_file, output_file)
136
136
  else
137
137
  begin
138
- response = self.class.shared_rack.get(URI.escape(resource.destination_path))
138
+ response = self.class.shared_rack.get(URI.escape(resource.request_path))
139
139
 
140
140
  if response.status == 200
141
141
  create_file(output_file, binary_encode(response.body))
@@ -123,12 +123,9 @@ module Middleman
123
123
  # @param [Hash] opts
124
124
  # @return [String]
125
125
  def render_template(path, locs={}, opts={}, blocks=[])
126
- # Detect the remdering engine from the extension
127
126
  extension = File.extname(path)
128
127
  engine = extension[1..-1].to_sym
129
128
 
130
- # Store last engine for later (could be inside nested renders)
131
- @current_engine, engine_was = engine, @current_engine
132
129
  if defined?(::I18n)
133
130
  old_locale = ::I18n.locale
134
131
  ::I18n.locale = opts[:lang] if opts[:lang]
@@ -171,7 +168,6 @@ module Middleman
171
168
  # Pop all the saved variables from earlier as we may be returning to a
172
169
  # previous render (layouts, partials, nested layouts).
173
170
  ::I18n.locale = old_locale if defined?(::I18n)
174
- @current_engine = engine_was
175
171
  @content_blocks = nil
176
172
  @current_locs = nil
177
173
  @current_opts = nil
@@ -238,6 +234,13 @@ module Middleman
238
234
  def render_individual_file(path, locs = {}, opts = {}, context = self, &block)
239
235
  path = path.to_s
240
236
 
237
+ # Detect the remdering engine from the extension
238
+ extension = File.extname(path)
239
+ engine = extension[1..-1].to_sym
240
+
241
+ # Store last engine for later (could be inside nested renders)
242
+ context.current_engine, engine_was = engine, context.current_engine
243
+
241
244
  # Save current buffer for later
242
245
  @_out_buf, _buf_was = "", @_out_buf
243
246
 
@@ -283,6 +286,7 @@ module Middleman
283
286
  ensure
284
287
  # Reset stored buffer
285
288
  @_out_buf = _buf_was
289
+ context.current_engine = engine_was
286
290
  end
287
291
 
288
292
  # Get the template data from a path
@@ -394,13 +398,13 @@ module Middleman
394
398
  # Save current buffer for later
395
399
  @_out_buf, _buf_was = "", @_out_buf
396
400
 
397
- layout_path = locate_layout(layout_name, current_engine)
401
+ layout_path = locate_layout(layout_name, self.current_engine)
398
402
 
399
403
  extension = File.extname(layout_path)
400
404
  engine = extension[1..-1].to_sym
401
405
 
402
406
  # Store last engine for later (could be inside nested renders)
403
- @current_engine, engine_was = engine, @current_engine
407
+ self.current_engine, engine_was = engine, self.current_engine
404
408
 
405
409
  begin
406
410
  content = if block_given?
@@ -415,13 +419,19 @@ module Middleman
415
419
 
416
420
  concat_safe_content render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
417
421
  ensure
418
- @current_engine = engine_was
422
+ self.current_engine = engine_was
419
423
  end
420
424
 
421
425
  # The currently rendering engine
422
426
  # @return [Symbol, nil]
423
427
  def current_engine
424
- @current_engine ||= nil
428
+ @_current_engine ||= nil
429
+ end
430
+
431
+ # The currently rendering engine
432
+ # @return [Symbol, nil]
433
+ def current_engine=(v)
434
+ @_current_engine = v
425
435
  end
426
436
 
427
437
  # Find a template on disk given a output path
@@ -2,6 +2,7 @@ require "middleman-core/sitemap/store"
2
2
  require "middleman-core/sitemap/resource"
3
3
 
4
4
  require "middleman-core/sitemap/extensions/on_disk"
5
+ require "middleman-core/sitemap/extensions/request_endpoints"
5
6
  require "middleman-core/sitemap/extensions/proxies"
6
7
  require "middleman-core/sitemap/extensions/ignores"
7
8
 
@@ -16,6 +17,7 @@ module Middleman
16
17
  # Once registered
17
18
  def registered(app)
18
19
 
20
+ app.register Middleman::Sitemap::Extensions::RequestEndpoints
19
21
  app.register Middleman::Sitemap::Extensions::Proxies
20
22
  app.register Middleman::Sitemap::Extensions::Ignores
21
23
 
@@ -0,0 +1,177 @@
1
+ module Middleman
2
+
3
+ module Sitemap
4
+
5
+ module Extensions
6
+
7
+ module RequestEndpoints
8
+
9
+ # Setup extension
10
+ class << self
11
+
12
+ # Once registered
13
+ def registered(app)
14
+ # ::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
15
+
16
+ # Include methods
17
+ app.send :include, InstanceMethods
18
+ end
19
+
20
+ alias :included :registered
21
+ end
22
+
23
+ # module ResourceInstanceMethods
24
+ # # Whether this page is a proxy
25
+ # # @return [Boolean]
26
+ # def proxy?
27
+ # !!@proxied_to
28
+ # end
29
+
30
+ # # Set this page to proxy to a target path
31
+ # # @param [String] target
32
+ # # @return [void]
33
+ # def proxy_to(target)
34
+ # target = ::Middleman::Util.normalize_path(target)
35
+ # raise "You can't proxy #{path} to itself!" if target == path
36
+ # @proxied_to = target
37
+ # end
38
+
39
+ # # The path of the page this page is proxied to, or nil if it's not proxied.
40
+ # # @return [String]
41
+ # def proxied_to
42
+ # @proxied_to
43
+ # end
44
+
45
+ # # The resource for the page this page is proxied to. Throws an exception
46
+ # # if there is no resource.
47
+ # # @return [Sitemap::Resource]
48
+ # def proxied_to_resource
49
+ # proxy_resource = store.find_resource_by_path(proxied_to)
50
+
51
+ # unless proxy_resource
52
+ # raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
53
+ # end
54
+
55
+ # if proxy_resource.proxy?
56
+ # raise "You can't proxy #{path} to #{proxied_to} which is itself a proxy."
57
+ # end
58
+
59
+ # proxy_resource
60
+ # end
61
+
62
+ # def get_source_file
63
+ # if proxy?
64
+ # proxied_to_resource.source_file
65
+ # else
66
+ # super
67
+ # end
68
+ # end
69
+
70
+ # def content_type
71
+ # mime_type = super
72
+ # return mime_type if mime_type
73
+
74
+ # if proxy?
75
+ # proxied_to_resource.content_type
76
+ # else
77
+ # nil
78
+ # end
79
+ # end
80
+ # end
81
+
82
+ module InstanceMethods
83
+ def endpoint_manager
84
+ @_endpoint_manager ||= EndpointManager.new(self)
85
+ end
86
+
87
+ def endpoint(*args, &block)
88
+ endpoint_manager.create_endpoint(*args, &block)
89
+ end
90
+ end
91
+
92
+ # Manages the list of proxy configurations and manipulates the sitemap
93
+ # to include new resources based on those configurations
94
+ class EndpointManager
95
+ def initialize(app)
96
+ @app = app
97
+ @endpoints = {}
98
+ end
99
+
100
+ # Setup a proxy from a path to a target
101
+ # @param [String] path
102
+ # @param [Hash] The :path value gives a request path if it
103
+ # differs from the output path
104
+ # @return [void]
105
+ def create_endpoint(path, opts={}, &block)
106
+ endpoint = {
107
+ :request_path => path
108
+ }
109
+
110
+ if block_given?
111
+ endpoint[:output] = block
112
+ else
113
+ endpoint[:request_path] = opts[:path] if opts.has_key?(:path)
114
+ end
115
+
116
+ @endpoints[path] = endpoint
117
+
118
+ @app.sitemap.rebuild_resource_list!(:added_endpoint)
119
+ end
120
+
121
+ # Update the main sitemap resource list
122
+ # @return [void]
123
+ def manipulate_resource_list(resources)
124
+ resources + @endpoints.map do |path, config|
125
+ r = EndpointResource.new(
126
+ @app.sitemap,
127
+ path,
128
+ config[:request_path]
129
+ )
130
+ r.output = config[:output] if config.has_key?(:output)
131
+ r
132
+ end
133
+ end
134
+ end
135
+
136
+ class EndpointResource < ::Middleman::Sitemap::Resource
137
+ attr_accessor :output
138
+
139
+ def initialize(store, path, source_file)
140
+ @request_path = ::Middleman::Util.normalize_path(source_file)
141
+
142
+ super(store, path)
143
+ end
144
+
145
+ def template?
146
+ true
147
+ end
148
+
149
+ def render(*args, &block)
150
+ return self.output.call if self.output
151
+ end
152
+
153
+ def request_path
154
+ @request_path
155
+ end
156
+
157
+ def binary?
158
+ false
159
+ end
160
+
161
+ def raw_data
162
+ {}
163
+ end
164
+
165
+ def ignored?
166
+ false
167
+ end
168
+
169
+ def metadata
170
+ @local_metadata.dup
171
+ end
172
+
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -105,6 +105,10 @@ module Middleman
105
105
  File.extname(path)
106
106
  end
107
107
 
108
+ def request_path
109
+ self.destination_path
110
+ end
111
+
108
112
  # Render this resource
109
113
  # @return [String]
110
114
  def render(opts={}, locs={}, &block)
@@ -36,6 +36,9 @@ module Middleman
36
36
  # Register classes which can manipulate the main site map list
37
37
  register_resource_list_manipulator(:on_disk, Middleman::Sitemap::Extensions::OnDisk.new(self))
38
38
 
39
+ # Request Endpoints
40
+ register_resource_list_manipulator(:request_endpoints, @app.endpoint_manager)
41
+
39
42
  # Proxies
40
43
  register_resource_list_manipulator(:proxies, @app.proxy_manager)
41
44
  end
@@ -1,3 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem "middleman", "~><%= Middleman::VERSION %>"
4
+
5
+ # Cross-templating language block fix for Ruby 1.8
6
+ platforms :mri_18 do
7
+ gem "ruby18_source_location"
8
+ end
@@ -8,4 +8,9 @@ gem "middleman", "~><%= Middleman::VERSION %>"
8
8
  gem "middleman-livereload", "~> 3.1.0"
9
9
 
10
10
  # For faster file watcher updates:
11
- # gem "wdm", "~> 0.1.0") # Windows
11
+ # gem "wdm", "~> 0.1.0") # Windows
12
+
13
+ # Cross-templating language block fix for Ruby 1.8
14
+ platforms :mri_18 do
15
+ gem "ruby18_source_location"
16
+ end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  # Current Version
3
3
  # @return [String]
4
- VERSION = '3.1.0.rc.3' unless const_defined?(:VERSION)
4
+ VERSION = '3.1.0.rc.4' unless const_defined?(:VERSION)
5
5
  end
@@ -1,3 +1,14 @@
1
+ # Required to hack around Padrino blocks within different template types.
2
+ require 'rbconfig'
3
+ if RUBY_VERSION =~ /1.8/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
4
+ begin
5
+ require 'ruby18_source_location'
6
+ rescue LoadError
7
+ $stderr.puts "Ruby 1.8 requires the 'ruby18_source_location' gem be added to your Gemfile"
8
+ exit(1)
9
+ end
10
+ end
11
+
1
12
  if !defined?(::Padrino::Helpers)
2
13
  require 'vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite'
3
14
  require 'vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers'
@@ -36,6 +47,28 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
36
47
 
37
48
  # The helpers
38
49
  helpers do
50
+
51
+ # Make all block content html_safe
52
+ def content_tag(name, content = nil, options = nil, &block)
53
+ mark_safe(super(name, mark_safe(content), options, &block))
54
+ end
55
+
56
+ def capture_html(*args, &block)
57
+ handler = auto_find_proper_handler(&block)
58
+ captured_block, captured_html = nil, ""
59
+ if handler && handler.is_type? && handler.block_is_type?(block)
60
+ captured_html, captured_block = handler.capture_from_template(*args, &block)
61
+ end
62
+ # invoking the block directly if there was no template
63
+ captured_html = block_given? && ( captured_block || block.call(*args) ) if captured_html.blank?
64
+ captured_html
65
+ end
66
+
67
+ def auto_find_proper_handler(&block)
68
+ engine = block_given? ? File.extname(block.source_location[0])[1..-1].to_sym : current_engine
69
+ ::Padrino::Helpers::OutputHelpers.handlers.map { |h| h.new(self) }.find { |h| h.engines.include?(engine) && h.is_type? }
70
+ end
71
+
39
72
  # Disable Padrino cache buster
40
73
  def asset_stamp
41
74
  false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.rc.3
4
+ version: 3.1.0.rc.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-08 00:00:00.000000000 Z
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -546,6 +546,10 @@ files:
546
546
  - fixtures/layouts-dir-app/source/layouts/layout.erb
547
547
  - fixtures/layouts-dir-app/source/layouts2/layout.erb
548
548
  - fixtures/layouts-dir-app/source/nested/layouts2/layout.erb
549
+ - fixtures/link-to-app/config.rb
550
+ - fixtures/link-to-app/source/link_to_erb.html.erb
551
+ - fixtures/link-to-app/source/link_to_haml.html.haml
552
+ - fixtures/link-to-app/source/link_to_slim.html.slim
549
553
  - fixtures/liquid-app/config.rb
550
554
  - fixtures/liquid-app/data/test.yml
551
555
  - fixtures/liquid-app/data/test2.json
@@ -633,6 +637,9 @@ files:
633
637
  - fixtures/more-instance-vars-app/source/instance-var-set.html.erb
634
638
  - fixtures/more-instance-vars-app/source/layout.erb
635
639
  - fixtures/more-instance-vars-app/source/no-instance-var.html.erb
640
+ - fixtures/more-markdown-app/source/layouts/layout.erb
641
+ - fixtures/more-markdown-app/source/with_layout.markdown
642
+ - fixtures/more-markdown-app/source/with_layout_erb.markdown.erb
636
643
  - fixtures/more-preview-app/config.rb
637
644
  - fixtures/more-preview-app/source/content.html.erb
638
645
  - fixtures/more-preview-app/source/layout.erb
@@ -940,6 +947,7 @@ files:
940
947
  - lib/middleman-core/sitemap/extensions/ignores.rb
941
948
  - lib/middleman-core/sitemap/extensions/on_disk.rb
942
949
  - lib/middleman-core/sitemap/extensions/proxies.rb
950
+ - lib/middleman-core/sitemap/extensions/request_endpoints.rb
943
951
  - lib/middleman-core/sitemap/extensions/traversal.rb
944
952
  - lib/middleman-core/sitemap/queryable.rb
945
953
  - lib/middleman-core/sitemap/resource.rb
@@ -1736,6 +1744,10 @@ test_files:
1736
1744
  - fixtures/layouts-dir-app/source/layouts/layout.erb
1737
1745
  - fixtures/layouts-dir-app/source/layouts2/layout.erb
1738
1746
  - fixtures/layouts-dir-app/source/nested/layouts2/layout.erb
1747
+ - fixtures/link-to-app/config.rb
1748
+ - fixtures/link-to-app/source/link_to_erb.html.erb
1749
+ - fixtures/link-to-app/source/link_to_haml.html.haml
1750
+ - fixtures/link-to-app/source/link_to_slim.html.slim
1739
1751
  - fixtures/liquid-app/config.rb
1740
1752
  - fixtures/liquid-app/data/test.yml
1741
1753
  - fixtures/liquid-app/data/test2.json
@@ -1823,6 +1835,9 @@ test_files:
1823
1835
  - fixtures/more-instance-vars-app/source/instance-var-set.html.erb
1824
1836
  - fixtures/more-instance-vars-app/source/layout.erb
1825
1837
  - fixtures/more-instance-vars-app/source/no-instance-var.html.erb
1838
+ - fixtures/more-markdown-app/source/layouts/layout.erb
1839
+ - fixtures/more-markdown-app/source/with_layout.markdown
1840
+ - fixtures/more-markdown-app/source/with_layout_erb.markdown.erb
1826
1841
  - fixtures/more-preview-app/config.rb
1827
1842
  - fixtures/more-preview-app/source/content.html.erb
1828
1843
  - fixtures/more-preview-app/source/layout.erb