Move renderers into core, but don't require gems and only register templates if gems present

This commit is contained in:
Thomas Reynolds 2012-05-28 13:19:40 -07:00
parent c3c662cf44
commit 67e78f20c7
13 changed files with 174 additions and 175 deletions

View file

@ -1,5 +1,3 @@
require "middleman-core/renderers/erb"
# Shutup Tilt Warnings
# @private
class Tilt::Template
@ -22,7 +20,47 @@ module Middleman
app.send :include, InstanceMethods
# Activate custom renderers
require "middleman-core/renderers/erb"
app.register Middleman::Renderers::ERb
# CoffeeScript Support
begin
require "middleman-core/renderers//coffee_script"
app.register Middleman::Renderers::CoffeeScript
rescue LoadError
end
# Haml Support
begin
require "middleman-core/renderers//haml"
app.register Middleman::Renderers::Haml
rescue LoadError
end
# Sass Support
begin
require "middleman-core/renderers//sass"
app.register Middleman::Renderers::Sass
rescue LoadError
end
# Markdown Support
require "middleman-core/renderers//markdown"
app.register Middleman::Renderers::Markdown
# Liquid Support
begin
require "middleman-core/renderers//liquid"
app.register Middleman::Renderers::Liquid
rescue LoadError
end
# Slim Support
begin
require "middleman-core/renderers//slim"
app.register Middleman::Renderers::Slim
rescue LoadError
end
end
alias :included :registered

View file

@ -1,3 +1,6 @@
# Require gem
require "coffee_script"
module Middleman
module Renderers
@ -8,9 +11,6 @@ module Middleman
class << self
# Once registered
def registered(app)
# Require gem
require "coffee_script"
app.before_configuration do
template_extensions :coffee => :js
end
@ -18,7 +18,6 @@ module Middleman
# Tell Tilt to use it as well (for inline scss blocks)
::Tilt.register 'coffee', DebuggingCoffeeScriptTemplate
::Tilt.prefer(DebuggingCoffeeScriptTemplate)
end
alias :included :registered
end

View file

@ -1,3 +1,6 @@
# Require gem
require "haml"
module Middleman
module Renderers
@ -8,9 +11,6 @@ module Middleman
class << self
# Once registered
def registered(app)
# Require gem
require "haml"
app.before_configuration do
template_extensions :haml => :html
end

View file

@ -0,0 +1,35 @@
# Require Gem
require "liquid"
module Middleman
module Renderers
# Liquid Renderer
module Liquid
# Setup extension
class << self
# Once registerd
def registered(app)
app.before_configuration do
template_extensions :liquid => :html
end
# After config, setup liquid partial paths
app.after_configuration do
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
# Convert data object into a hash for liquid
sitemap.provides_metadata %r{\.liquid$} do |path|
{ :locals => { :data => data.to_h } }
end
end
end
alias :included :registered
end
end
end
end

View file

@ -0,0 +1,57 @@
module Middleman
module Renderers
# Markdown renderer
module Markdown
# Setup extension
class << self
# Once registered
def registered(app)
# Set our preference for a markdown engine
# TODO: Find a JRuby-compatible version
app.set :markdown_engine, :maruku
app.set :markdown_engine_prefix, ::Tilt
app.before_configuration do
template_extensions :markdown => :html,
:mdown => :html,
:md => :html,
:mkd => :html,
:mkdn => :html
end
# Once configuration is parsed
app.after_configuration do
begin
# Look for the user's preferred engine
if markdown_engine == :redcarpet
require "middleman-core/renderers//redcarpet"
::Tilt.prefer(::Middleman::Renderers::RedcarpetTemplate)
elsif markdown_engine.nil?
# Map symbols to classes
markdown_engine_klass = if markdown_engine.is_a? Symbol
engine = markdown_engine.to_s
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
markdown_engine_prefix.const_get("#{engine}Template")
else
markdown_engine_prefix
end
# Tell tilt to use that engine
::Tilt.prefer(markdown_engine_klass)
end
rescue LoadError
$stderr.puts "Requested Markdown engine (#{markdown_engine}) not found. Maybe the gem needs to be installed and required?"
end
end
end
alias :included :registered
end
end
end
end

View file

@ -30,8 +30,6 @@ module Middleman
end
renderer.new(render_options)
end
end

View file

@ -1,3 +1,5 @@
require "sass"
module Middleman
module Renderers
@ -9,8 +11,6 @@ module Middleman
# Once registered
def registered(app)
require "sass"
# Default sass options
app.set :sass, {}
@ -80,7 +80,6 @@ module Middleman
:scss
end
end
end
end
end

View file

@ -0,0 +1,30 @@
# Load gem
require "slim"
module Middleman
module Renderers
# Slim renderer
module Slim
# Setup extension
class << self
# Once registered
def registered(app)
app.before_configuration do
template_extensions :slim => :html
end
# Setup Slim options to work with partials
::Slim::Engine.set_default_options(
:buffer => '@_out_buf',
:generator => ::Temple::Generators::StringBuffer
)
end
alias :included :registered
end
end
end
end

View file

@ -12,34 +12,6 @@ module Middleman
# Once registered
def registered(app, options={})
###
# Setup renderers
###
# CoffeeScript Support
require "middleman-more/renderers/coffee_script"
Middleman::Application.register Middleman::Renderers::CoffeeScript
# Haml Support
require "middleman-more/renderers/haml"
Middleman::Application.register Middleman::Renderers::Haml
# Sass Support
require "middleman-more/renderers/sass"
Middleman::Application.register Middleman::Renderers::Sass
# Markdown Support
require "middleman-more/renderers/markdown"
Middleman::Application.register Middleman::Renderers::Markdown
# Liquid Support
require "middleman-more/renderers/liquid"
Middleman::Application.register Middleman::Renderers::Liquid
# Slim Support
require "middleman-more/renderers/slim"
Middleman::Application.register Middleman::Renderers::Slim
###
# Setup Core Extensions
###

View file

@ -1,40 +0,0 @@
module Middleman
module Renderers
# Liquid Renderer
module Liquid
# Setup extension
class << self
# Once registerd
def registered(app)
# Liquid is not included in the default gems,
# but we'll support it if available.
begin
# Require Gem
require "liquid"
app.before_configuration do
template_extensions :liquid => :html
end
# After config, setup liquid partial paths
app.after_configuration do
::Liquid::Template.file_system = ::Liquid::LocalFileSystem.new(source_dir)
# Convert data object into a hash for liquid
sitemap.provides_metadata %r{\.liquid$} do |path|
{ :locals => { :data => data.to_h } }
end
end
rescue LoadError
end
end
alias :included :registered
end
end
end
end

View file

@ -1,54 +0,0 @@
module Middleman
module Renderers
# Markdown renderer
module Markdown
# Setup extension
class << self
# Once registered
def registered(app)
# Set our preference for a markdown engine
# TODO: Find a JRuby-compatible version
app.set :markdown_engine, :maruku
app.set :markdown_engine_prefix, ::Tilt
app.before_configuration do
template_extensions :markdown => :html,
:mdown => :html,
:md => :html,
:mkd => :html,
:mkdn => :html
end
# Once configuration is parsed
app.after_configuration do
# Look for the user's preferred engine
if markdown_engine == :redcarpet
require "middleman-more/renderers/redcarpet"
::Tilt.prefer(::Middleman::Renderers::RedcarpetTemplate)
elsif markdown_engine.nil?
# Map symbols to classes
markdown_engine_klass = if markdown_engine.is_a? Symbol
engine = markdown_engine.to_s
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
markdown_engine_prefix.const_get("#{engine}Template")
else
markdown_engine_prefix
end
# Tell tilt to use that engine
::Tilt.prefer(markdown_engine_klass)
end
end
end
alias :included :registered
end
end
end
end

View file

@ -1,35 +0,0 @@
module Middleman
module Renderers
# Slim renderer
module Slim
# Setup extension
class << self
# Once registered
def registered(app)
# Slim is not included in the default gems,
# but we'll support it if available.
begin
# Load gem
require "slim"
app.before_configuration do
template_extensions :slim => :html
end
# Setup Slim options to work with partials
::Slim::Engine.set_default_options(
:buffer => '@_out_buf',
:generator => ::Temple::Generators::StringBuffer
)
rescue LoadError
end
end
alias :included :registered
end
end
end
end