2011-11-19 01:17:14 +01:00
|
|
|
require "middleman/vendor/padrino-core-0.10.5/lib/padrino-core/support_lite"
|
|
|
|
require 'i18n'
|
|
|
|
require 'enumerator'
|
|
|
|
require 'active_support/core_ext/string/conversions' # to_date
|
|
|
|
require 'active_support/core_ext/float/rounding' # round
|
|
|
|
require 'active_support/option_merger' # with_options
|
|
|
|
require 'active_support/core_ext/object/with_options' # with_options
|
|
|
|
require 'active_support/inflector' # humanize
|
|
|
|
|
|
|
|
FileSet.glob_require('../vendor/padrino-helpers-0.10.5/lib/padrino-helpers/**/*.rb', __FILE__)
|
|
|
|
|
2011-07-06 18:50:34 +02:00
|
|
|
module Middleman::CoreExtensions::DefaultHelpers
|
2010-09-07 03:48:25 +02:00
|
|
|
class << self
|
|
|
|
def registered(app)
|
2011-11-19 01:17:14 +01:00
|
|
|
app.helpers ::Padrino::Helpers::OutputHelpers
|
|
|
|
app.helpers ::Padrino::Helpers::TagHelpers
|
|
|
|
app.helpers ::Padrino::Helpers::AssetTagHelpers
|
|
|
|
app.helpers ::Padrino::Helpers::FormHelpers
|
|
|
|
app.helpers ::Padrino::Helpers::FormatHelpers
|
|
|
|
app.helpers ::Padrino::Helpers::RenderHelpers
|
|
|
|
app.helpers ::Padrino::Helpers::NumberHelpers
|
|
|
|
app.helpers ::Padrino::Helpers::TranslationHelpers
|
|
|
|
|
2011-07-06 18:50:34 +02:00
|
|
|
app.helpers Helpers
|
2010-09-07 03:48:25 +02:00
|
|
|
end
|
|
|
|
alias :included :registered
|
2009-10-23 02:25:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
module Helpers
|
2011-06-23 18:32:10 +02:00
|
|
|
def auto_stylesheet_link_tag(separator="/")
|
|
|
|
auto_tag(:css, separator) do |path|
|
2011-06-22 21:13:35 +02:00
|
|
|
stylesheet_link_tag path
|
2011-06-23 18:32:10 +02:00
|
|
|
end
|
2011-06-22 21:13:35 +02:00
|
|
|
end
|
2011-06-23 18:32:10 +02:00
|
|
|
|
2011-06-22 21:13:35 +02:00
|
|
|
def auto_javascript_include_tag(separator="/")
|
|
|
|
auto_tag(:js, separator) do |path|
|
|
|
|
javascript_include_tag path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_tag(asset_ext, separator="/", asset_dir=nil)
|
|
|
|
if asset_dir.nil?
|
|
|
|
asset_dir = case asset_ext
|
2011-11-18 09:34:56 +01:00
|
|
|
when :js then self.js_dir
|
|
|
|
when :css then self.css_dir
|
2011-06-22 21:13:35 +02:00
|
|
|
end
|
|
|
|
end
|
2011-11-19 05:49:59 +01:00
|
|
|
|
2011-06-23 18:32:10 +02:00
|
|
|
# If the basename of the request as no extension, assume we are serving a
|
|
|
|
# directory and join index_file to the path.
|
2011-11-19 05:49:59 +01:00
|
|
|
path = full_path(current_path.dup)
|
|
|
|
|
|
|
|
path = path.sub(%r{^/}, '')
|
2011-06-22 21:13:35 +02:00
|
|
|
path = path.gsub(File.extname(path), ".#{asset_ext}")
|
2009-12-28 21:03:38 +01:00
|
|
|
path = path.gsub("/", separator)
|
2009-11-03 21:34:57 +01:00
|
|
|
|
2011-11-19 05:49:59 +01:00
|
|
|
matching_file = resolve_template(File.join(asset_dir, path))
|
|
|
|
|
|
|
|
yield path if matching_file
|
2009-11-03 21:34:57 +01:00
|
|
|
end
|
2011-06-22 21:13:35 +02:00
|
|
|
|
2009-11-03 21:34:57 +01:00
|
|
|
def page_classes
|
2011-11-18 09:34:56 +01:00
|
|
|
path = current_path.dup
|
|
|
|
path << self.index_file if path.match(%r{/$})
|
2009-11-03 21:34:57 +01:00
|
|
|
path = path.gsub(%r{^/}, '')
|
2009-10-23 02:25:15 +02:00
|
|
|
|
|
|
|
classes = []
|
|
|
|
parts = path.split('.')[0].split('/')
|
|
|
|
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
|
2009-11-03 21:34:57 +01:00
|
|
|
|
2009-10-23 02:25:15 +02:00
|
|
|
classes.join(' ')
|
|
|
|
end
|
|
|
|
|
2010-09-07 03:48:25 +02:00
|
|
|
# Padrino's asset handling needs to pass through ours
|
|
|
|
def asset_path(kind, source)
|
|
|
|
return source if source =~ /^http/
|
|
|
|
asset_folder = case kind
|
2011-11-18 09:34:56 +01:00
|
|
|
when :css then self.css_dir
|
|
|
|
when :js then self.js_dir
|
|
|
|
when :images then self.images_dir
|
2010-09-07 03:48:25 +02:00
|
|
|
else kind.to_s
|
|
|
|
end
|
|
|
|
source = source.to_s.gsub(/\s/, '')
|
2011-06-14 22:54:59 +02:00
|
|
|
ignore_extension = (kind == :images) # don't append extension
|
2010-09-07 03:48:25 +02:00
|
|
|
source << ".#{kind}" unless ignore_extension or source =~ /\.#{kind}/
|
|
|
|
result_path = source if source =~ %r{^/} # absolute path
|
|
|
|
result_path ||= asset_url(source, asset_folder)
|
|
|
|
timestamp = asset_timestamp(result_path)
|
|
|
|
"#{result_path}#{timestamp}"
|
|
|
|
end
|
2009-10-23 02:25:15 +02:00
|
|
|
end
|
2011-06-22 21:13:35 +02:00
|
|
|
end
|