Sha256: 630de48ea7c88dde16f9688628b591a1f82d2d0b05c0a9af19f7e72c26c99ae1

Contents?: true

Size: 959 Bytes

Versions: 7

Compression:

Stored size: 959 Bytes

Contents

module Poirot
  module AssetHelper
    def template_include_tag(*sources)
      sources.collect do |source|
        template = File.open(resolve_partial_path(source), "rb")
        content_tag :script, template.read.html_safe, :type => "text/mustache", :id => "#{template_name(source).parameterize.dasherize}-template"
      end.join("\n").html_safe
    end

    private

    def is_absolute_path?(source)
      source.to_s =~ /^\//
    end

    def template_name(source)
      if is_absolute_path?(source)
        source.to_s.split('/').last
      else
        source
      end
    end

    def resolve_partial_path(source)
      if is_absolute_path?(source)
        segments = source.to_s.split('/')
        partial_name = "_#{segments.pop}.html.mustache"
        segments << partial_name
        Rails.root.join('app/views', *segments)
      else
        Rails.root.join('app/views', controller_name, "_#{source}.html.mustache")
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
nulogy-poirot-0.2.4.1 lib/poirot/asset_helper.rb
poirot-0.2.4 lib/poirot/asset_helper.rb
poirot-0.2.3 lib/poirot/asset_helper.rb
poirot-0.2.2 lib/poirot/asset_helper.rb
poirot-0.2.1 lib/poirot/asset_helper.rb
poirot-0.2.0 lib/poirot/asset_helper.rb
poirot-0.1.0 lib/poirot/asset_helper.rb