Sha256: 6073df96086b1a41dee06e4b81ce8466f42003d9dd75197cb68c6aaeef280c19

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'fileutils'

module Pyro
  module Assets
    def self.included(base)
      base.extend(ClassMethods)
    end
  
    module ClassMethods
  
      def template *args
        args = args.first
        
        templates = []
        templates << "./lib/#{args[:src]}" if args[:src]
        if args[:dir]
          Dir.glob("./lib/#{args[:dir]}/**/*.{hbs, handlebars,x-handlebars}").each do |f|
            templates << f
          end
        end
      
        tags = ''
        templates.each do |t|
          contents  = File.read t
          
          if args[:name]
            name = args[:name]
          elsif args[:src]
            name = t.split('/').last.split('.').first
          elsif args[:dir]
            name = t.sub("./lib/#{args[:dir]}/", '').split('.').first
          else
            name = 'name-not-found'
          end
          
          tags << "\n<script type='text/x-handlebars' data-template-name='#{name}'>\n"
          tags << contents
          tags << "\n</script>\n"
        end
      
        tags
      end
  
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pyro-0.8.1 lib/pyro/assets/templates.rb