Class: Sinatra::Minify::Package
- Inherits:
-
Object
- Object
- Sinatra::Minify::Package
- Extended by:
- Forwardable
- Defined in:
- lib/sinatra/minify/package.rb
Instance Attribute Summary collapse
-
#compressor ⇒ Object
readonly
Returns the value of attribute compressor.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.build(app_class = ::Main) ⇒ Object
Packages and minifies all of the files declared on config/assets.yml.
-
.clean(app_class = ::Main) ⇒ Object
Deletes all the different packaged and minified files You may pass in a different application object e.g.
Instance Method Summary collapse
- #files ⇒ Object
- #html ⇒ Object
-
#initialize(type, set, app_class = ::Main) ⇒ Package
constructor
A new instance of Package.
Constructor Details
#initialize(type, set, app_class = ::Main) ⇒ Package
Returns a new instance of Package.
48 49 50 51 52 53 54 55 56 |
# File 'lib/sinatra/minify/package.rb', line 48 def initialize(type, set, app_class = ::Main) @type = type.to_s @app_class = app_class @set = set.to_s @config = Config.new(@type, app_class) @filename = "#{set}.min.#{type}" @compressor = Compressor.new(@type, public_dir(@filename), self) end |
Instance Attribute Details
#compressor ⇒ Object (readonly)
Returns the value of attribute compressor.
6 7 8 |
# File 'lib/sinatra/minify/package.rb', line 6 def compressor @compressor end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/sinatra/minify/package.rb', line 7 def filename @filename end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
5 6 7 |
# File 'lib/sinatra/minify/package.rb', line 5 def set @set end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/sinatra/minify/package.rb', line 4 def type @type end |
Class Method Details
.build(app_class = ::Main) ⇒ Object
Packages and minifies all of the files declared on config/assets.yml
Returns all of the minified files
29 30 31 32 33 34 |
# File 'lib/sinatra/minify/package.rb', line 29 def build(app_class = ::Main) ret = [] ret << all(:js, app_class).map { |p| p.compressor.build } ret << all(:css, app_class).map { |p| p.compressor.build } ret.flatten end |
.clean(app_class = ::Main) ⇒ Object
Deletes all the different packaged and minified files You may pass in a different application object e.g.
Sinatra::Minify::Package.clean(HelloWorld)
as long as the appication has registered Sinatra::Minify
The files will be based on config/assets.yml
See test/fixtures/exampleapp/config/assets.yml for an example
21 22 23 24 |
# File 'lib/sinatra/minify/package.rb', line 21 def clean(app_class = ::Main) all(:js, app_class).each { |p| p.compressor.clean } all(:css, app_class).each { |p| p.compressor.clean } end |
Instance Method Details
#files ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sinatra/minify/package.rb', line 68 def files specs = sets[set] globs = Array(specs).map { |s| public_dir(s) } globs.map { |glob| list = Dir[glob] if list.empty? and glob.include?('*') raise GlobNoMatchError, "The spec `#{glob}` does not match any files." end list.empty? ? glob : list }.flatten.uniq end |
#html ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/sinatra/minify/package.rb', line 58 def html if @app_class.minify? file = public_dir(filename) mtime = File.exists?(file) ? File.mtime(file).to_i : '' asset_include_tag public_url(filename), mtime else enumerate_all_assets end end |