Module: CompEx::Rails::AssetPipeline
- Defined in:
- lib/compex/rails/asset_pipeline.rb
Constant Summary collapse
- STYLE_DIR =
"compex/styles"- SCRIPT_DIR =
"compex/scripts"
Class Method Summary collapse
- .logical_paths(base_dir, glob) ⇒ Object
- .prepare!(app) ⇒ Object
- .write_assets(subdir, assets) ⇒ Object
Class Method Details
.logical_paths(base_dir, glob) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/compex/rails/asset_pipeline.rb', line 38 def self.logical_paths(base_dir, glob) return [] unless base_dir && Dir.exist?(base_dir) Dir[File.join(base_dir, glob)].map do |full_path| File.join(File.basename(File.dirname(full_path)), File.basename(full_path)) end end |
.prepare!(app) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/compex/rails/asset_pipeline.rb', line 9 def self.prepare!(app) return unless app.config.respond_to?(:assets) styles_dir = write_assets(STYLE_DIR, CompEx::ComponentRegistry.gather_styles) scripts_dir = write_assets(SCRIPT_DIR, CompEx::ComponentRegistry.gather_scripts) [styles_dir, scripts_dir].compact.each do |dir| app.config.assets.paths << dir end app.config.assets.precompile += logical_paths(styles_dir, "*.css") app.config.assets.precompile += logical_paths(scripts_dir, "*.js") end |
.write_assets(subdir, assets) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/compex/rails/asset_pipeline.rb', line 23 def self.write_assets(subdir, assets) return if assets.blank? root = Rails.root.join("tmp", "compex", "assets", subdir) FileUtils.mkdir_p(root) assets.each do |logical_name, source| ext = logical_name.start_with?("c_") ? ".css" : ".js" path = root.join("#{logical_name}#{ext}") File.write(path, source) end root.to_s end |