Class: Cyborg::Plugin
- Inherits:
-
Object
- Object
- Cyborg::Plugin
- Defined in:
- lib/cyborg/plugin.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#gem ⇒ Object
readonly
Returns the value of attribute gem.
-
#javascripts ⇒ Object
readonly
Returns the value of attribute javascripts.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stylesheets ⇒ Object
readonly
Returns the value of attribute stylesheets.
-
#svgs ⇒ Object
readonly
Returns the value of attribute svgs.
Instance Method Summary collapse
- #add_assets ⇒ Object
- #asset_root ⇒ Object
- #assets ⇒ Object
- #build ⇒ Object
- #config(options) ⇒ Object
- #create_engine ⇒ Object
- #expand_asset_paths ⇒ Object
-
#initialize(options) ⇒ Plugin
constructor
A new instance of Plugin.
- #parent_module ⇒ Object
- #watch ⇒ Object
Constructor Details
#initialize(options) ⇒ Plugin
Returns a new instance of Plugin.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cyborg/plugin.rb', line 6 def initialize() @name = .delete(:name) @module_name = parent_module.name @gem = Gem.loaded_specs[@name] config() # Store the gem path for access later when overriding root parent_module.instance_variable_set(:@gem_path, root) add_assets @engine = create_engine if defined?(Rails) end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def destination @destination end |
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def engine @engine end |
#gem ⇒ Object (readonly)
Returns the value of attribute gem.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def gem @gem end |
#javascripts ⇒ Object (readonly)
Returns the value of attribute javascripts.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def javascripts @javascripts end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def module_name @module_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def name @name end |
#stylesheets ⇒ Object (readonly)
Returns the value of attribute stylesheets.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def stylesheets @stylesheets end |
#svgs ⇒ Object (readonly)
Returns the value of attribute svgs.
3 4 5 |
# File 'lib/cyborg/plugin.rb', line 3 def svgs @svgs end |
Instance Method Details
#add_assets ⇒ Object
44 45 46 47 48 |
# File 'lib/cyborg/plugin.rb', line 44 def add_assets @javascripts = Assets::Javascripts.new(self, paths[:javascripts]) @stylesheets = Assets::Stylesheets.new(self, paths[:stylesheets]) @svgs = Assets::Svgs.new(self, paths[:svgs]) end |
#asset_root ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/cyborg/plugin.rb', line 97 def asset_root if Cyborg.production? plugin.production_asset_root else plugin.asset_root end end |
#assets ⇒ Object
50 51 52 |
# File 'lib/cyborg/plugin.rb', line 50 def assets [@svgs, @stylesheets, @javascripts] end |
#build ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cyborg/plugin.rb', line 54 def build Command.from_root { FileUtils.mkdir_p(File.join(destination, asset_root)) } threads = [] assets.each do |asset| threads << Thread.new { asset.build } end threads end |
#config(options) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cyborg/plugin.rb', line 70 def config() = { production_asset_root: "/assets/#{@name}", asset_root: "/assets/#{@name}", destination: "public/", root: @gem.full_gem_path, version: @gem.version.to_s, paths: { stylesheets: "app/assets/stylesheets/#{@name}", javascripts: "app/assets/javascripts/#{@name}", svgs: "app/assets/svgs/#{@name}", } }.merge() .each do |k,v| set_instance(k.to_s,v) end end |
#create_engine ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cyborg/plugin.rb', line 20 def create_engine # Create a new Rails::Engine return parent_module.const_set('Engine', Class.new(Rails::Engine) do def get_plugin_path parent = Object.const_get(self.class.to_s.split('::').first) path = parent.instance_variable_get("@gem_path") Pathname.new path end def config @config ||= Rails::Engine::Configuration.new(get_plugin_path) end initializer "#{name.to_s.downcase}.static_assets" do |app| app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public") end end) end |
#expand_asset_paths ⇒ Object
90 91 92 93 94 95 |
# File 'lib/cyborg/plugin.rb', line 90 def @paths.each do |type, path| @paths[type] = File.join(root, path) end @destination = File.join(root, @destination) end |
#parent_module ⇒ Object
40 41 42 |
# File 'lib/cyborg/plugin.rb', line 40 def parent_module Object.const_get(self.class.to_s.split('::').first) end |
#watch ⇒ Object
66 67 68 |
# File 'lib/cyborg/plugin.rb', line 66 def watch assets.map(&:watch) end |