Sha256: 77a1f0634f47b839059ccc6cf3300e7013c88a84214bdeb1d0b379fa784e1b55
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
require "json" require "active_support" module Bower class Project < Struct.new(:name, :version, :assets) include ActiveSupport::Inflector class Creator attr_reader :src def initialize(src) @src = src end def create! cmd = Bower::Command.new(src) cmd.install! prj_json = JSON.parse(cmd.list!) dep_paths = JSON.parse(cmd.list_paths!) cwd = prj_json.fetch("canonicalDir") pkg_meta = prj_json.fetch("pkgMeta") name = pkg_meta.fetch("name") version = pkg_meta.fetch("version") prj = Bower::Project.new(name, version, []) prj.assets += build_assets(cwd, pkg_meta["main"]) # current prj.assets += build_dep_assets(cwd, dep_paths) prj end private def build_assets(cwd, paths) Array(paths).map do |p| full_path(cwd, p) end end def build_dep_assets(cwd, dep_paths) dep_paths.map do |_, p| build_assets(cwd, p) end.flatten end def full_path(cwd, path) File.expand_path File.join(cwd, path) end end def initialize(*args) super(*args) self.assets ||= [] end def dir_name dasherize(name) end def rails_assets_dir_name @dir_name ||= "rails-assets-#{dir_name}" end def rails_assets_namespace @namespace ||= "RailsAssets#{classify(underscore(name))}" end def js_assets @js_assets ||= assets.select { |a| File.extname(a) == ".js" } end def css_assets @css_assets ||= assets.select { |a| [ ".scss", ".less", ".sass", ".css" ].include?(File.extname(a)) } end def font_assets @font_assets ||= assets.select { |a| [ ".eot", ".svg", ".ttf", ".woff" ].include?(File.extname(a)) } end def self.create!(src) Creator.new(src).create! end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rab-0.0.1 | lib/rab/bower/project.rb |