Sha256: 33eb98c87cb4de05379f8ef65ed16143ada95c2058843c72dd531b886b336190
Contents?: true
Size: 1.94 KB
Versions: 4
Compression:
Stored size: 1.94 KB
Contents
require "json" require 'fileutils' module BowerRails class Dsl def self.config=(conf) @config = conf end def self.config @config end def self.evalute(file) inst = new inst.eval_file(file) inst end def initialize @dependencies = {} @groups = [] @root_path = BowerRails::Dsl.config[:root_path] || File.expand_path("./") @assets_path = BowerRails::Dsl.config[:assets_path] || "/assets/javascripts" end def eval_file(file) contents = File.open(file,"r").read instance_eval(contents, file.to_s, 1) end def directories @dependencies.keys end def dependencies @dependencies end def group(*args, &blk) @groups.concat [args] yield ensure args.each { @groups.pop } end def js(name, *args) options = Hash === args.last ? args.pop : {} version = args.first || "latest" @groups = ["lib"] if @groups.empty? @groups.each do |g| g_options = Hash === g.last ? g.pop : {} assets_path = g_options[:assets_path] || @assets_path g_norm = normalize_location_path(g.first,assets_path) @dependencies[g_norm] ||= {} @dependencies[g_norm][name] = version end end def to_json(location) dependencies_to_json @dependencies[normalize_location_path(location)] end def write_bower_json @dependencies.each do |dir,data| FileUtils.mkdir_p dir unless File.directory? dir File.open(File.join(dir,"bower.json"),"w") do |f| f.write(dependencies_to_json(data)) end end end private def dependencies_to_json(data) JSON.pretty_generate({ :dependencies => data }) end def assets_path(assets_path) @assets_path = assets_path end def normalize_location_path(loc,assets_path) File.join(@root_path,loc.to_s,assets_path) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
bower-rails-0.4.0 | lib/bower-rails/dsl.rb |
bower-rails-0.3.3 | lib/bower-rails/dsl.rb |
bower-rails-0.3.2 | lib/bower-rails/dsl.rb |
bower-rails-0.3.1 | lib/bower-rails/dsl.rb |