convert default helpers to new ext

This commit is contained in:
Thomas Reynolds 2013-04-20 14:36:38 -07:00
parent 1d1f37d764
commit 01e85b8bf7
2 changed files with 214 additions and 225 deletions

View file

@ -21,7 +21,7 @@ module Middleman
# Setup default helpers # Setup default helpers
require "middleman-more/core_extensions/default_helpers" require "middleman-more/core_extensions/default_helpers"
Middleman::Application.register Middleman::CoreExtensions::DefaultHelpers Middleman::CoreExtensions::DefaultHelpers.new(app)
# i18n # i18n
require "i18n" require "i18n"

View file

@ -1,14 +1,9 @@
require 'active_support/core_ext/object/to_query' class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
module Middleman def initialize(app, options_hash={}, &block)
module CoreExtensions super
# Built-in helpers
module DefaultHelpers
# Extension registered require 'active_support/core_ext/object/to_query'
class << self
# @private
def registered(app)
require 'padrino-helpers' require 'padrino-helpers'
app.helpers ::Padrino::Helpers::OutputHelpers app.helpers ::Padrino::Helpers::OutputHelpers
@ -19,15 +14,11 @@ module Middleman
app.helpers ::Padrino::Helpers::RenderHelpers app.helpers ::Padrino::Helpers::RenderHelpers
app.helpers ::Padrino::Helpers::NumberHelpers app.helpers ::Padrino::Helpers::NumberHelpers
app.helpers Helpers
app.config.define_setting :relative_links, false, 'Whether to generate relative links instead of absolute ones' app.config.define_setting :relative_links, false, 'Whether to generate relative links instead of absolute ones'
end end
alias :included :registered
end
# The helpers # The helpers
module Helpers helpers do
# Disable Padrino cache buster # Disable Padrino cache buster
def asset_stamp def asset_stamp
false false
@ -78,7 +69,7 @@ module Middleman
def page_classes def page_classes
path = current_path.dup path = current_path.dup
path << index_file if path.end_with?('/') path << index_file if path.end_with?('/')
path = Util.strip_leading_slash(path) path = ::Middleman::Util.strip_leading_slash(path)
classes = [] classes = []
parts = path.split('.').first.split('/') parts = path.split('.').first.split('/')
@ -153,7 +144,7 @@ module Middleman
# Try to find a sitemap resource corresponding to the desired path # Try to find a sitemap resource corresponding to the desired path
this_resource = current_resource # store in a local var to save work this_resource = current_resource # store in a local var to save work
if path_or_resource.is_a?(Sitemap::Resource) if path_or_resource.is_a?(::Middleman::Sitemap::Resource)
resource = path_or_resource resource = path_or_resource
resource_url = url resource_url = url
elsif this_resource && uri.path elsif this_resource && uri.path
@ -239,6 +230,4 @@ module Middleman
super super
end end
end end
end
end
end end