# Required to hack around Padrino blocks within different template types.require'rbconfig'ifRUBY_VERSION=~/1.8/&&RbConfig::CONFIG['ruby_install_name']=='ruby'beginrequire'ruby18_source_location'rescueLoadError$stderr.puts"Ruby 1.8 requires the 'ruby18_source_location' gem be added to your Gemfile"exit(1)endendif!defined?(::Padrino::Helpers)require'vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite'require'vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers'endclassPadrino::Helpers::OutputHelpers::ErbHandler# Force Erb capture not to use safebufferdefcapture_from_template(*args,&block)self.output_buffer,_buf_was="",self.output_buffercaptured_block=block.call(*args)ret=eval("@_out_buf",block.binding)self.output_buffer=_buf_was[ret,captured_block]endendclassMiddleman::CoreExtensions::DefaultHelpers<::Middleman::Extensiondefinitialize(app,options_hash={},&block)superrequire'active_support/core_ext/object/to_query'app.helpers::Padrino::Helpers::OutputHelpersapp.helpers::Padrino::Helpers::TagHelpersapp.helpers::Padrino::Helpers::AssetTagHelpersapp.helpers::Padrino::Helpers::FormHelpersapp.helpers::Padrino::Helpers::FormatHelpersapp.helpers::Padrino::Helpers::RenderHelpersapp.helpers::Padrino::Helpers::NumberHelpers# app.helpers ::Padrino::Helpers::TranslationHelpersapp.helpers::Padrino::Helpers::Breadcrumbsapp.config.define_setting:relative_links,false,'Whether to generate relative links instead of absolute ones'end# The helpershelpersdo# Make all block content html_safedefcontent_tag(name,content=nil,options=nil,&block)ifblock_given?options=contentifcontent.is_a?(Hash)content=capture_html(&block)endoptions=parse_data_options(name,options)attributes=tag_attributes(options)output=ActiveSupport::SafeBuffer.newoutput.safe_concat"<#{name}#{attributes}>"ifcontent.respond_to?(:each)&&!content.is_a?(String)content.each{|c|output.safe_concatc;output.safe_concatNEWLINE}elseoutput.safe_concat"#{content}"endoutput.safe_concat"</#{name}>"block_is_template?(block)?concat_content(output):outputenddefcapture_html(*args,&block)handler=auto_find_proper_handler(&block)captured_block,captured_html=nil,""ifhandler&&handler.is_type?&&handler.block_is_type?(block)captured_html,captured_block=handler.capture_from_template(*args,&block)end# invoking the block directly if there was no templatecaptured_html=block_given?&&(captured_block||block.call(*args))ifcaptured_html.blank?captured_htmlenddefauto_find_proper_handler(&block)engine=block_given??File.extname(block.source_location[0])[1..-1].to_sym:current_engine::Padrino::Helpers::OutputHelpers.handlers.map{|h|h.new(self)}.find{|h|h.engines.include?(engine)&&h.is_type?}end# Disable Padrino cache busterdefasset_stampfalseend# Output a stylesheet link tag based on the current path## @return [String]defauto_stylesheet_link_tagauto_tag(:css)do|path|stylesheet_link_tagpathendend# Output a javascript tag based on the current path## @return [String]defauto_javascript_include_tagauto_tag(:js)do|path|javascript_include_tagpathendend# Output a stylesheet link tag based on the current path## @param [Symbol] asset_ext The type of asset# @param [String] asset_dir Where to look for assets# @return [void]defauto_tag(asset_ext,asset_dir=nil)ifasset_dir.nil?asset_dir=caseasset_extwhen:jsthenjs_dirwhen:cssthencss_direndend# If the basename of the request as no extension, assume we are serving a# directory and join index_file to the path.path=File.join(asset_dir,current_path)path=path.sub(/#{Regexp.escape(File.extname(path))}$/,".#{asset_ext}")yieldpathifsitemap.find_resource_by_path(path)end# Generate body css classes based on the current path## @return [String]defpage_classespath=current_path.duppath<<index_fileifpath.end_with?('/')path=::Middleman::Util.strip_leading_slash(path)classes=[]parts=path.split('.').first.split('/')parts.each_with_index{|path,i|classes<<parts.first(i+1).join('_')}classes.join(' ')end# Get the path of a file of a given type## @param [Symbol] kind The type of file# @param [String] source The path to the file# @return [String]defasset_path(kind,source)returnsourceifsource.to_s.include?('//')||source.to_s.start_with?('data:')asset_folder=casekindwhen:cssthencss_dirwhen:jsthenjs_dirwhen:imagesthenimages_dirwhen:fontsthenfonts_direlsekind.to_sendsource=source.to_s.tr(' ','')ignore_extension=(kind==:images||kind==:fonts)# don't append extensionsource<<".#{kind}"unlessignore_extension||source.end_with?(".#{kind}")asset_folder=""ifsource.start_with?('/')# absolute pathasset_url(source,asset_folder)end# Get the URL of an asset given a type/prefix## @param [String] path The path (such as "photo.jpg")# @param [String] prefix The type prefix (such as "images")# @return [String] The fully qualified asset urldefasset_url(path,prefix="")# Don't touch assets which already have a full pathifpath.include?('//')orpath.start_with?('data:')pathelse# rewrite paths to use their destination pathpath=File.join(prefix,path)ifresource=sitemap.find_resource_by_path(path)resource.urlelseFile.join(config[:http_prefix],path)endendend# Given a source path (referenced either absolutely or relatively)# or a Resource, this will produce the nice URL configured for that# path, respecting :relative_links, directory indexes, etc.defurl_for(path_or_resource,options={})::Middleman::Util.url_for(self,path_or_resource,options)end# Overload the regular link_to to be sitemap-aware - if you# reference a source path, either absolutely or relatively,# you'll get that resource's nice URL. Also, there is a# :relative option which, if set to true, will produce# relative URLs instead of absolute URLs. You can also add## config[:relative_links] = true## to config.rb to have all links default to relative.## There is also a :query option that can be used to append a# query string, which can be expressed as either a String,# or a Hash which will be turned into URL parameters.deflink_to(*args,&block)url_arg_index=block_given??0:1options_index=block_given??1:2ifblock_given?&&args.size>2raiseArgumentError.new("Too many arguments to link_to(url, options={}, &block)")endifurl=args[url_arg_index]options=args[options_index]||{}raiseArgumentError.new("Options must be a hash")unlessoptions.is_a?(Hash)# Transform the url through our magic url_for methodargs[url_arg_index]=url_for(url,options)endsuper(*args,&block)end# Modified Padrino form_for that uses Middleman's url_for# to transform the URL.defform_tag(url,options={},&block)url=url_for(url,options)superendendend