class BaiduUeditorRails::AssetInstaller
Constants
- ASSETS
Public Class Methods
new(target, manifest_path)
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 7 def initialize(target, manifest_path) @target = target @manifest_path = manifest_path || target end
Public Instance Methods
install()
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 12 def install cleanup_assets copy_assets append_to_manifest manifest.write end
Private Instance Methods
append_to_manifest()
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 39 def append_to_manifest asset_files.each do |file| manifest.append(logical_path(file), file) end end
asset_files()
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 45 def asset_files Pathname.glob("#{ASSETS}/**/*").select(&:file?) end
cleanup_assets()
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 25 def cleanup_assets manifest.each(/^ueditor\//) do |asset| manifest.remove(asset) if index_asset?(asset) manifest.remove_digest(asset) do |src, dest| move_asset(src, dest) end end end
copy_assets()
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 35 def copy_assets FileUtils.cp_r(ASSETS, @target, :preserve => true) end
index_asset?(asset)
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 60 def index_asset?(asset) asset =~ /\/index\.js$/ end
logical_path(file)
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 49 def logical_path(file) file.relative_path_from(ASSETS.parent).to_s end
manifest()
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 21 def manifest @manifest ||= AssetManifest.load(@manifest_path) end
move_asset(src, dest)
click to toggle source
# File lib/baidu_ueditor_rails/asset_installer.rb, line 53 def move_asset(src, dest) src = File.join(@target, src) dest = File.join(@target, dest) FileUtils.mv(src, dest, :force => true) if src != dest && File.exists?(src) end