Cleanup renderers
This commit is contained in:
parent
2297100d9e
commit
874ebc13c9
|
@ -1,25 +1,30 @@
|
|||
# Require gem
|
||||
require "haml"
|
||||
|
||||
# Haml Renderer
|
||||
module Middleman::Renderers::Haml
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Add haml helpers to context
|
||||
app.send :include, ::Haml::Helpers
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Haml Renderer
|
||||
module Haml
|
||||
|
||||
app.before_configuration do
|
||||
template_extensions :haml => :html
|
||||
end
|
||||
# Setup extension
|
||||
class << self
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Require gem
|
||||
require "haml"
|
||||
|
||||
app.before_configuration do
|
||||
template_extensions :haml => :html
|
||||
end
|
||||
|
||||
# Add haml helpers to context
|
||||
app.send :include, ::Haml::Helpers
|
||||
|
||||
# Setup haml helper paths
|
||||
app.ready do
|
||||
init_haml_helpers
|
||||
# Setup haml helper paths
|
||||
app.ready do
|
||||
init_haml_helpers
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
|
@ -1,35 +1,40 @@
|
|||
# Liquid Renderer
|
||||
module Middleman::Renderers::Liquid
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Liquid Renderer
|
||||
module Liquid
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
# 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
|
||||
# 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"
|
||||
|
||||
# Require Gem
|
||||
require "liquid"
|
||||
app.before_configuration do
|
||||
template_extensions :liquid => :html
|
||||
end
|
||||
|
||||
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)
|
||||
# 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 } }
|
||||
# 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
|
||||
rescue LoadError
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
|
@ -1,50 +1,57 @@
|
|||
# Markdown renderer
|
||||
module Middleman::Renderers::Markdown
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Require redcarpet gem
|
||||
require "redcarpet"
|
||||
# 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, :redcarpet
|
||||
app.set :markdown_engine_prefix, ::Tilt
|
||||
|
||||
# Forcably disable Redcarpet1 support.
|
||||
# Tilt defaults to this if available, but the compat
|
||||
# layer disables extensions.
|
||||
Object.send(:remove_const, :RedcarpetCompat) if defined? ::RedcarpetCompat
|
||||
|
||||
# Set our preference for a markdown engine
|
||||
app.set :markdown_engine, :redcarpet
|
||||
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
|
||||
unless markdown_engine.nil?
|
||||
|
||||
# Map symbols to classes
|
||||
if markdown_engine.is_a? Symbol
|
||||
engine = markdown_engine.to_s
|
||||
engine = engine == "rdiscount" ? "RDiscount" : engine.camelize
|
||||
markdown_engine = markdown_engine_prefix.const_get("#{engine}Template")
|
||||
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
|
||||
unless 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)
|
||||
|
||||
if markdown_engine == :redcarpet
|
||||
# Forcably disable Redcarpet1 support.
|
||||
# Tilt defaults to this if available, but the compat
|
||||
# layer disables extensions.
|
||||
Object.send(:remove_const, :RedcarpetCompat) if defined? ::RedcarpetCompat
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Tell tilt to use that engine
|
||||
::Tilt.prefer(markdown_engine)
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
|
@ -1,81 +1,88 @@
|
|||
# Pull in gems
|
||||
require "sprockets"
|
||||
require "sprockets-sass"
|
||||
require "sass"
|
||||
|
||||
# Stick with Compass' asset functions
|
||||
Sprockets::Sass.add_sass_functions = false
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# Sass renderer
|
||||
module Sass
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
require "sass"
|
||||
|
||||
# Sass renderer
|
||||
module Middleman::Renderers::Sass
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
|
||||
# Once registered
|
||||
def registered(app)
|
||||
# Default sass options
|
||||
app.set :sass, {}
|
||||
# Stick with Compass' asset functions
|
||||
::Sprockets::Sass.add_sass_functions = false
|
||||
|
||||
# Default sass options
|
||||
app.set :sass, {}
|
||||
|
||||
app.before_configuration do
|
||||
template_extensions :scss => :css,
|
||||
:sass => :css
|
||||
app.before_configuration do
|
||||
template_extensions :scss => :css,
|
||||
:sass => :css
|
||||
end
|
||||
|
||||
# Tell Sprockets to use our custom Sass template
|
||||
::Sprockets.register_engine ".sass", SassPlusCSSFilenameTemplate
|
||||
|
||||
# Tell Tilt to use it as well (for inline sass blocks)
|
||||
::Tilt.register 'sass', SassPlusCSSFilenameTemplate
|
||||
::Tilt.prefer(SassPlusCSSFilenameTemplate)
|
||||
|
||||
# Tell Sprockets to use our custom Scss template
|
||||
::Sprockets.register_engine ".scss", ScssPlusCSSFilenameTemplate
|
||||
|
||||
# Tell Tilt to use it as well (for inline scss blocks)
|
||||
::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
|
||||
::Tilt.prefer(ScssPlusCSSFilenameTemplate)
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
# A SassTemplate for Sprockets/Tilt which outputs debug messages
|
||||
class SassPlusCSSFilenameTemplate < ::Sprockets::Sass::SassTemplate
|
||||
# A SassTemplate for Sprockets/Tilt which outputs debug messages
|
||||
class SassPlusCSSFilenameTemplate < ::Sprockets::Sass::SassTemplate
|
||||
|
||||
# Add exception messaging
|
||||
# @param [Class] context
|
||||
# @param [Hash] locals
|
||||
# @return [String]
|
||||
def evaluate(context, locals, &block)
|
||||
begin
|
||||
super
|
||||
rescue Sass::SyntaxError => e
|
||||
Sass::SyntaxError.exception_to_css(e, :full_exception => true)
|
||||
# Add exception messaging
|
||||
# @param [Class] context
|
||||
# @param [Hash] locals
|
||||
# @return [String]
|
||||
def evaluate(context, locals, &block)
|
||||
begin
|
||||
super
|
||||
rescue Sass::SyntaxError => e
|
||||
Sass::SyntaxError.exception_to_css(e, :full_exception => true)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
# Change Sass path, for url functions, to the build folder if we're building
|
||||
# @return [Hash]
|
||||
def sass_options
|
||||
location_of_sass_file = File.expand_path(@context.source, @context.root)
|
||||
|
||||
parts = basename.split('.')
|
||||
parts.pop
|
||||
css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
||||
|
||||
super.merge(:css_filename => css_filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
# Change Sass path, for url functions, to the build folder if we're building
|
||||
# @return [Hash]
|
||||
def sass_options
|
||||
location_of_sass_file = File.expand_path(@context.source, @context.root)
|
||||
|
||||
parts = basename.split('.')
|
||||
parts.pop
|
||||
css_filename = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
||||
|
||||
super.merge(:css_filename => css_filename)
|
||||
end
|
||||
end
|
||||
|
||||
# Tell Sprockets to use our custom Sass template
|
||||
::Sprockets.register_engine ".sass", SassPlusCSSFilenameTemplate
|
||||
|
||||
# Tell Tilt to use it as well (for inline sass blocks)
|
||||
::Tilt.register 'sass', SassPlusCSSFilenameTemplate
|
||||
::Tilt.prefer(SassPlusCSSFilenameTemplate)
|
||||
|
||||
# SCSS version of the above template
|
||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||
# SCSS version of the above template
|
||||
class ScssPlusCSSFilenameTemplate < SassPlusCSSFilenameTemplate
|
||||
|
||||
# Define the expected syntax for the template
|
||||
# @return [Symbol]
|
||||
def syntax
|
||||
:scss
|
||||
# Define the expected syntax for the template
|
||||
# @return [Symbol]
|
||||
def syntax
|
||||
:scss
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# Tell Sprockets to use our custom Scss template
|
||||
::Sprockets.register_engine ".scss", ScssPlusCSSFilenameTemplate
|
||||
|
||||
# Tell Tilt to use it as well (for inline scss blocks)
|
||||
::Tilt.register 'scss', ScssPlusCSSFilenameTemplate
|
||||
::Tilt.prefer(ScssPlusCSSFilenameTemplate)
|
||||
end
|
|
@ -1,27 +1,35 @@
|
|||
# Slim renderer
|
||||
module Middleman::Renderers::Slim
|
||||
|
||||
# Setup extension
|
||||
class << self
|
||||
module Middleman
|
||||
module Renderers
|
||||
|
||||
# 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"
|
||||
# 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
|
||||
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
|
||||
|
||||
# Setup Slim options to work with partials
|
||||
Slim::Engine.set_default_options(:buffer => '@_out_buf', :generator => Temple::Generators::StringBuffer) if defined?(Slim)
|
||||
rescue LoadError
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
||||
|
||||
alias :included :registered
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue