add more content_for helpers, disable caching for now
This commit is contained in:
parent
ddb15b2e35
commit
e2fdd9a4d3
16
features/content_for.feature
Normal file
16
features/content_for.feature
Normal file
|
@ -0,0 +1,16 @@
|
|||
Feature: Support content_for and yield_content helpers
|
||||
|
||||
Scenario: content_for works as expected in erb
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/content_for_erb.html"
|
||||
Then I should see "In Layout: I am the yielded content erb"
|
||||
|
||||
Scenario: content_for works as expected in haml
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/content_for_haml.html"
|
||||
Then I should see "In Layout: I am the yielded content haml"
|
||||
|
||||
Scenario: content_for works as expected in slim
|
||||
Given the Server is running at "test-app"
|
||||
When I go to "/content_for_slim.html"
|
||||
Then I should see "In Layout: I am the yielded content slim"
|
|
@ -15,6 +15,12 @@ page "/target_ignore.html", :proxy => "/should_be_ignored3.html", :ignore => tru
|
|||
end
|
||||
end
|
||||
|
||||
with_layout :content_for do
|
||||
page "/content_for_erb.html"
|
||||
page "/content_for_haml.html"
|
||||
page "/content_for_slim.html"
|
||||
end
|
||||
|
||||
with_layout false do
|
||||
page "/markdown.html"
|
||||
page "/relative_image.html"
|
||||
|
|
5
fixtures/test-app/source/content_for_erb.html.erb
Normal file
5
fixtures/test-app/source/content_for_erb.html.erb
Normal file
|
@ -0,0 +1,5 @@
|
|||
<% content_for :from_template do %>
|
||||
I am the yielded content erb
|
||||
<% end %>
|
||||
|
||||
I am in the template
|
4
fixtures/test-app/source/content_for_haml.html.haml
Normal file
4
fixtures/test-app/source/content_for_haml.html.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
- content_for :from_template do
|
||||
= "I am the yielded content haml"
|
||||
|
||||
%p I am in the template
|
4
fixtures/test-app/source/content_for_slim.html.slim
Normal file
4
fixtures/test-app/source/content_for_slim.html.slim
Normal file
|
@ -0,0 +1,4 @@
|
|||
- content_for :from_template do
|
||||
| I am the yielded content slim
|
||||
|
||||
| I am in the template
|
4
fixtures/test-app/source/layouts/content_for.erb
Normal file
4
fixtures/test-app/source/layouts/content_for.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
In Layout: <%= yield_content(:from_template).chomp.strip %>
|
||||
|
||||
In Template:
|
||||
<%= yield %>
|
|
@ -14,6 +14,7 @@ module Middleman
|
|||
|
||||
# Custom Renderers
|
||||
module Renderers
|
||||
autoload :Haml, "middleman/renderers/haml"
|
||||
autoload :Sass, "middleman/renderers/sass"
|
||||
autoload :Markdown, "middleman/renderers/markdown"
|
||||
autoload :ERb, "middleman/renderers/erb"
|
||||
|
|
|
@ -373,13 +373,13 @@ class Middleman::Base
|
|||
# @param [String] Request path
|
||||
# @return [String] Path with index file if necessary
|
||||
def full_path(path)
|
||||
cache.fetch(:full_path, path) do
|
||||
# cache.fetch(:full_path, path) do
|
||||
parts = path ? path.split('/') : []
|
||||
if parts.last.nil? || parts.last.split('.').length == 1
|
||||
path = File.join(path, index_file)
|
||||
end
|
||||
"/" + path.sub(%r{^/}, '')
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
# Add a new mime-type for a specific extension
|
||||
|
|
|
@ -47,7 +47,7 @@ module Middleman
|
|||
# Remove a specific key
|
||||
# @param Anything Hash can use as a key
|
||||
def remove(*key)
|
||||
@cache.delete(key) if @cache.has_key?(key)
|
||||
@cache.delete(key)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,6 +12,7 @@ module Middleman::CoreExtensions::Rendering
|
|||
app.send :include, InstanceMethods
|
||||
|
||||
# Activate custom renderers
|
||||
app.register Middleman::Renderers::Haml
|
||||
app.register Middleman::Renderers::Sass
|
||||
app.register Middleman::Renderers::Markdown
|
||||
app.register Middleman::Renderers::ERb
|
||||
|
@ -24,18 +25,35 @@ module Middleman::CoreExtensions::Rendering
|
|||
end
|
||||
|
||||
module InstanceMethods
|
||||
def initialize
|
||||
file_changed %r{^source/} do |file|
|
||||
path = File.expand_path(file, root)
|
||||
# cache.remove(:raw_template, path.to_sym)
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def render_template(path, locs={}, opts={})
|
||||
extension = File.extname(path)
|
||||
engine = extension[1..-1].to_sym
|
||||
|
||||
@current_engine, engine_was = engine, @current_engine
|
||||
@_out_buf, _buf_was = "", @_out_buf
|
||||
|
||||
content = render_individual_file(path, locs, opts)
|
||||
|
||||
extension = File.extname(path)
|
||||
needs_layout = !%w(.js .css .txt).include?(extension)
|
||||
engine = extension[1..-1].to_sym
|
||||
|
||||
if needs_layout && layout_path = fetch_layout(engine, opts)
|
||||
content = render_individual_file(layout_path, locs, opts) { content }
|
||||
end
|
||||
|
||||
content
|
||||
ensure
|
||||
@current_engine = engine_was
|
||||
@_out_buf = _buf_was
|
||||
@content_blocks = nil
|
||||
end
|
||||
|
||||
# Sinatra/Padrino render method signature.
|
||||
|
@ -79,22 +97,25 @@ module Middleman::CoreExtensions::Rendering
|
|||
# @private
|
||||
def render_individual_file(path, locs = {}, opts = {}, &block)
|
||||
path = path.to_s
|
||||
body = cache.fetch(:raw_template, path) do
|
||||
body = #cache.fetch(:raw_template, path) do
|
||||
# $stderr.puts "reading: #{path}"
|
||||
File.read(path)
|
||||
end
|
||||
# end
|
||||
|
||||
options = opts.merge(options_for_ext(File.extname(path)))
|
||||
extension = File.extname(path)
|
||||
options = opts.merge(options_for_ext(extension))
|
||||
options[:outvar] ||= '@_out_buf'
|
||||
|
||||
template = cache.fetch(:compiled_template, options, body) do
|
||||
template = #cache.fetch(:compiled_template, options, body) do
|
||||
::Tilt.new(path, 1, options) { body }
|
||||
end
|
||||
# end
|
||||
|
||||
template.render(self, locs, &block)
|
||||
end
|
||||
|
||||
# @private
|
||||
def options_for_ext(ext)
|
||||
cache.fetch(:options_for_ext, ext) do
|
||||
# cache.fetch(:options_for_ext, ext) do
|
||||
options = {}
|
||||
|
||||
extension_class = ::Tilt[ext]
|
||||
|
@ -105,7 +126,7 @@ module Middleman::CoreExtensions::Rendering
|
|||
end
|
||||
|
||||
options
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
# @private
|
||||
|
@ -166,10 +187,14 @@ module Middleman::CoreExtensions::Rendering
|
|||
layout_path
|
||||
end
|
||||
|
||||
def current_engine
|
||||
@current_engine ||= nil
|
||||
end
|
||||
|
||||
# @private
|
||||
def resolve_template(request_path, options={})
|
||||
request_path = request_path.to_s
|
||||
cache.fetch(:resolve_template, request_path, options) do
|
||||
# cache.fetch(:resolve_template, request_path, options) do
|
||||
relative_path = request_path.sub(%r{^/}, "")
|
||||
on_disk_path = File.expand_path(relative_path, self.source_dir)
|
||||
|
||||
|
@ -203,7 +228,7 @@ module Middleman::CoreExtensions::Rendering
|
|||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,8 +11,6 @@ module Middleman::CoreExtensions::Sitemap
|
|||
|
||||
module InstanceMethods
|
||||
def initialize
|
||||
::Middleman::Sitemap::Template.cache.clear
|
||||
|
||||
file_changed do |file|
|
||||
sitemap.touch_file(file)
|
||||
end
|
||||
|
|
17
lib/middleman/renderers/haml.rb
Normal file
17
lib/middleman/renderers/haml.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Middleman::Renderers::Haml
|
||||
class << self
|
||||
def registered(app)
|
||||
require "haml"
|
||||
app.send :include, ::Haml::Helpers
|
||||
app.send :include, InstanceMethods
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def initialize
|
||||
super
|
||||
init_haml_helpers
|
||||
end
|
||||
end
|
||||
end
|
|
@ -123,7 +123,6 @@ module Middleman::Sitemap
|
|||
|
||||
protected
|
||||
def extensionless_path(file)
|
||||
@cache ||= ::Middleman::Cache.new
|
||||
@cache.fetch(:extensionless_path, file) do
|
||||
path = file.dup
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ module Middleman::Sitemap
|
|||
end
|
||||
|
||||
def metadata
|
||||
cache.fetch(:metadata, source_file) do
|
||||
# store.cache.fetch(:metadata, source_file) do
|
||||
metadata = { :options => {}, :locals => {} }
|
||||
app.provides_metadata.each do |callback, matcher|
|
||||
next if !matcher.nil? && !source_file.match(matcher)
|
||||
|
@ -39,7 +39,7 @@ module Middleman::Sitemap
|
|||
metadata = metadata.deep_merge(result)
|
||||
end
|
||||
metadata
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
def render(opts={}, locs={}, &block)
|
||||
|
@ -53,14 +53,5 @@ module Middleman::Sitemap
|
|||
app.instance_eval(&block) if block_given?
|
||||
app.render_template(source_file, locs, opts)
|
||||
end
|
||||
|
||||
protected
|
||||
def self.cache
|
||||
@_cache ||= ::Middleman::Cache.new
|
||||
end
|
||||
|
||||
def cache
|
||||
self.class.cache
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue