Class: Xmvc::Vendor
- Inherits:
-
Thor
- Object
- Thor
- Xmvc::Vendor
- Includes:
- Thor::Actions
- Defined in:
- lib/xmvc/vendor.rb,
lib/xmvc/vendor/plugin.rb
Overview
A base thor-extension for which to build vendors/plugins for the Xmvc framework Extensions must impmlement several methods including :install and :secretary. Vendors are run in a root-dir named after themselves through the Xmvc::Vendor class-method #vendor_name. A Vendor must at least provide a file named ‘vendor.yml’ in the root of its template namespace this file is used to define asset and meta-data
name: some-vendor
javascripts:
- App.js
- app/view/**/*.js
- app/model/*.js
- app/controller/*.js
Direct Known Subclasses
Defined Under Namespace
Classes: Error, Plugin, SpecNotFound
Constant Summary collapse
- CONFIG_FILENAME =
all vendors must implement vendor.yml in the same directory their extension lives
"vendor.yml"
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#css ⇒ Object
Returns the value of attribute css.
-
#js ⇒ Object
Returns the value of attribute js.
Class Method Summary collapse
- .asset_urls(vendor, environment = :development, ext = :js, host = nil) ⇒ Object
- .bundle_css(vendor) ⇒ Object
- .bundle_js(vendor, sec, root = Xmvc::PUBLIC_PATH) ⇒ Object
-
.install(options) ⇒ Xmvc::Vendor
Install a vendor.
-
.load(options) ⇒ Xmvc::Vendor
Loads and configures an Xmvc::Vendor instance.
-
.vendor_name(name = nil) ⇒ Object
get / set the vendor name.
Instance Method Summary collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
33 34 35 |
# File 'lib/xmvc/vendor.rb', line 33 def config @config end |
#css ⇒ Object
Returns the value of attribute css.
35 36 37 |
# File 'lib/xmvc/vendor.rb', line 35 def css @css end |
#js ⇒ Object
Returns the value of attribute js.
34 35 36 |
# File 'lib/xmvc/vendor.rb', line 34 def js @js end |
Class Method Details
.asset_urls(vendor, environment = :development, ext = :js, host = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/xmvc/vendor.rb', line 80 def asset_urls(vendor, environment = :development, ext = :js, host=nil) config = vendor.config host = config['host'] unless host type = Xmvc.asset_dir(ext) rs = [] # Note, we check config['host'] here, not host as defined above, since cachefly urls # override host requested as function param. Host as in http://extjs.cachefly.net/... if config['host'].include?("http://") config[type].each do |file| rs << cachefly_url(environment, config['host'], config['name'], file, config['version'], ext) end elsif host != Xmvc::PUBLIC_PATH rs << File.join("/#{host}", "#{config['name']}.#{ext.to_s}") else rs << Xmvc.build_path(environment, host, config['name'], config['version'], ext) end rs end |
.bundle_css(vendor) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/xmvc/vendor.rb', line 113 def bundle_css(vendor) vendor.destination_root = Xmvc::PUBLIC_PATH vendor.inside "stylesheets" do Xmvc.ui.warn(' - bundle css -- no implementation') end end |
.bundle_js(vendor, sec, root = Xmvc::PUBLIC_PATH) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/xmvc/vendor.rb', line 99 def bundle_js(vendor, sec, root=Xmvc::PUBLIC_PATH) config = vendor.config vendor.destination_root = root path = "" vendor.inside "javascripts" do vendor.empty_directory(config['name']) unless File.exists? config['name'] vendor.inside config['name'] do |dir| path = File.(File.join(dir, Xmvc.build_name(vendor.[:environment]||:development, config['name'], config['version'], :js))) sec.concatenation.save_to(path) end end path end |
.install(options) ⇒ Xmvc::Vendor
Install a vendor
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/xmvc/vendor.rb', line 50 def install() if vendor_name.empty? raise Vendor::Error.new("Vendors must specify a name using the class-method vendor_name") end prepare_vendor() do |vendor| vendor.say_status("install", vendor.class.to_s) vendor.invoke(:install) begin vendor.copy_file(CONFIG_FILENAME, CONFIG_FILENAME) unless File.exists? CONFIG_FILENAME rescue StandardError => e raise SpecNotFound.new("Vendors must have available in their source-directory, a file named 'vendor.yml' or the class-method #source_root defined, which provides the base-path to the location of vendor.yml. Xmvc::Vendor attempted to automatically copy this file into the installation directory.") end end end |
.load(options) ⇒ Xmvc::Vendor
Loads and configures an Xmvc::Vendor instance
70 71 72 |
# File 'lib/xmvc/vendor.rb', line 70 def load() prepare_vendor() end |
.vendor_name(name = nil) ⇒ Object
get / set the vendor name
42 43 44 |
# File 'lib/xmvc/vendor.rb', line 42 def vendor_name(name=nil) @name ||= name.to_s end |
Instance Method Details
#bundle(sec = secretary(:js)) ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/xmvc/vendor.rb', line 176 def bundle(sec = secretary(:js)) # ugly hack for root in order to satisfy both Sprockts helper and CLI. root = (self.class.vendor_name == "app") ? Xmvc::PUBLIC_PATH : "../#{Xmvc::PUBLIC_PATH}" self.class.bundle_js(self, sec, root) unless config['host'].include?('http://') self.class.bundle_css(self) unless config['host'].include?('http://') end |
#secretary(type = :js) ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'lib/xmvc/vendor.rb', line 165 def secretary(type = :js) say_status "secretary", self.class.to_s case type when :js then @secretary ||= Sprockets::Secretary.new({ :root => destination_root, :source_files => config["javascripts"] }) end end |