asset 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -17
- data/app.rb +6 -1
- data/asset.gemspec +2 -2
- data/lib/asset.rb +5 -1
- data/lib/assets/filters.rb +7 -0
- data/lib/assets/helpers.rb +9 -4
- data/lib/assets/item.rb +10 -5
- data/lib/assets/util.rb +15 -24
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45bfd8e5aba5d8941fc5dad1e7b6cfb13618f51e
|
4
|
+
data.tar.gz: fa9dfa2916357553683779b8988d60604fbd8a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3f53b15353d381dde1a06e2a798bcfcbab10bb3e5089d8bb3a216dcbb5d252830fe3a52d3e450374cd2dd0af7eec2a80563465a8e1d89eb8e24b9ea5ef97106
|
7
|
+
data.tar.gz: 6a6eec4c65c51c5b8bfc3803aecb63dbd743a94e892e113ff28799ebfd2cbd5784fb3e4b117d5bac88e0ca54886147149dfe5d1cf5716983330ba2a76f8e46ff
|
data/README.md
CHANGED
@@ -42,8 +42,7 @@ helpers Asset::Router
|
|
42
42
|
```yaml
|
43
43
|
# Install your manifest file in APP_ROOT/app/assets/manifest.yml
|
44
44
|
|
45
|
-
# Asset manifest. Only the files mentioned here will be
|
46
|
-
# Options are compress: true/false, bundle: true/false
|
45
|
+
# Asset manifest. Only the files mentioned here will be bundled.
|
47
46
|
css:
|
48
47
|
- app.css
|
49
48
|
- themes/themes.css
|
@@ -51,21 +50,6 @@ css:
|
|
51
50
|
js:
|
52
51
|
- app.js
|
53
52
|
- lib/cookie.js
|
54
|
-
|
55
|
-
# Example with options:
|
56
|
-
css:
|
57
|
-
- app.css:
|
58
|
-
# Compress = false will prevent the file from being compressed (default true)
|
59
|
-
- compress: true
|
60
|
-
# This will not be part of the bundle.js if bundle = false (default true)
|
61
|
-
- bundle: true
|
62
|
-
- themes/themes.css
|
63
|
-
|
64
|
-
js:
|
65
|
-
# The same options apply to JS files
|
66
|
-
- app.js:
|
67
|
-
- bundle: false
|
68
|
-
- lib/cookie.js
|
69
53
|
```
|
70
54
|
|
71
55
|
```erb
|
data/app.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class App < Sinatra::Base
|
2
2
|
|
3
|
-
|
3
|
+
helpers Asset::Helpers
|
4
4
|
|
5
5
|
configure do
|
6
6
|
# Settings
|
@@ -19,6 +19,7 @@ class App < Sinatra::Base
|
|
19
19
|
|
20
20
|
# Liquid setup
|
21
21
|
Liquid::Template.file_system = Liquid::LocalFileSystem.new(APP_VIEWS)
|
22
|
+
Liquid::Template.register_filter(::Asset::Filters)
|
22
23
|
|
23
24
|
# Set up loggers and tmp files
|
24
25
|
Dir.mkdir('./tmp') unless File.exists?('./tmp')
|
@@ -39,6 +40,10 @@ class App < Sinatra::Base
|
|
39
40
|
erb(:index)
|
40
41
|
end
|
41
42
|
|
43
|
+
get('/liquid') do
|
44
|
+
liquid(:index)
|
45
|
+
end
|
46
|
+
|
42
47
|
# Default not found page
|
43
48
|
not_found do
|
44
49
|
"404, Not found".tap{|m| puts m}
|
data/asset.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'asset'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2017-01-
|
3
|
+
s.version = '0.1.2'
|
4
|
+
s.date = '2017-01-18'
|
5
5
|
s.summary = "Compress and serve your CSS and JS automatically"
|
6
6
|
s.description = "The only thing you need for your assets."
|
7
7
|
s.authors = ["Fugroup Limited"]
|
data/lib/asset.rb
CHANGED
@@ -8,7 +8,7 @@ autoload :Tilt, 'tilt'
|
|
8
8
|
# @author: Vidar <vidar@fugroup.net>, Fugroup Ltd.
|
9
9
|
# @license: MIT, contributions are welcome.
|
10
10
|
module Asset
|
11
|
-
class << self; attr_accessor :mode, :path, :cache, :favicon, :robots, :manifest, :images, :debug; end
|
11
|
+
class << self; attr_accessor :mode, :path, :cache, :favicon, :robots, :manifest, :bundle, :images, :debug; end
|
12
12
|
|
13
13
|
# Default is development
|
14
14
|
@mode = ENV['RACK_ENV'] || 'development'
|
@@ -35,8 +35,12 @@ require_relative 'assets/item'
|
|
35
35
|
# Load the manifest
|
36
36
|
::Asset.manifest = ::Asset::Util.load_manifest
|
37
37
|
|
38
|
+
# Load the bundle
|
39
|
+
::Asset.bundle = YAML.load_file(File.join(::Asset.path, 'manifest.yml'))
|
40
|
+
|
38
41
|
# Load the images
|
39
42
|
::Asset.images = ::Asset::Util.load_images
|
40
43
|
|
41
44
|
require_relative 'assets/helpers'
|
45
|
+
require_relative 'assets/filters'
|
42
46
|
require_relative 'assets/router'
|
data/lib/assets/helpers.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module Asset
|
2
2
|
module Helpers
|
3
3
|
|
4
|
+
# Asset URL
|
5
|
+
def asset_url(path)
|
6
|
+
::Asset.manifest.find{|i| i.path == path}.src rescue path
|
7
|
+
end
|
8
|
+
|
4
9
|
# Script tags
|
5
10
|
def script_tag(*paths)
|
6
11
|
tag('js', *paths) do |src|
|
@@ -18,7 +23,9 @@ module Asset
|
|
18
23
|
# Image tags
|
19
24
|
def image_tag(path)
|
20
25
|
b = ::Asset.images[path] rescue nil
|
21
|
-
|
26
|
+
# Just slip through if the path starts with http(s) or //
|
27
|
+
src = path =~ /^(http[s]?)?:?\/\// ? path : %{/assets/images/#{path}}
|
28
|
+
%{<img src="#{src}#{b ? "?#{b}" : ''}">} rescue path
|
22
29
|
end
|
23
30
|
|
24
31
|
private
|
@@ -26,13 +33,11 @@ module Asset
|
|
26
33
|
# Build the tags
|
27
34
|
def tag(type, *paths, &block)
|
28
35
|
paths.map do |path|
|
29
|
-
|
30
36
|
# Yield the source back to the tag builder
|
31
37
|
item = ::Asset.manifest.find{|i| i.path == path}
|
32
38
|
|
33
39
|
# Src is same as path if item not found
|
34
|
-
item ? item.files.map{|
|
35
|
-
|
40
|
+
item ? item.files.map{|f| yield(asset_url(f))} : yield(path)
|
36
41
|
end.flatten.join("\n")
|
37
42
|
end
|
38
43
|
|
data/lib/assets/item.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Asset
|
2
2
|
class Item
|
3
3
|
|
4
|
-
attr_accessor :path, :type, :key, :modified, :
|
4
|
+
attr_accessor :path, :type, :key, :modified, :app, :name, :kpath
|
5
5
|
|
6
6
|
# Init
|
7
7
|
def initialize(*args)
|
8
|
-
@path, @type, @key, @modified
|
8
|
+
@path, @type, @key, @modified = args
|
9
9
|
@app = !!(@path =~ /^bundle\.(js|css)$/)
|
10
10
|
@name = @path.rpartition('.')[0]
|
11
11
|
@kpath = "#{@name}-#{kext}"
|
@@ -13,17 +13,22 @@ module Asset
|
|
13
13
|
|
14
14
|
# Get the files for this item
|
15
15
|
def files
|
16
|
-
(@app and !p?) ? bundle_files : [
|
16
|
+
(@app and !p?) ? bundle_files : [@path]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get the full path
|
20
|
+
def src
|
21
|
+
File.join('/assets', @type, (p? ? @kpath : @path))
|
17
22
|
end
|
18
23
|
|
19
24
|
# Get the files for the bundle
|
20
25
|
def bundle_files
|
21
|
-
@bundle_files ||= ::Asset.manifest.select{|i| i.type == @type and
|
26
|
+
@bundle_files ||= ::Asset.manifest.select{|i| ::Asset.bundle[type].include?(i.path) and i.type == @type and !i.app}.map{|i| i.path}
|
22
27
|
end
|
23
28
|
|
24
29
|
# Get the content. Pass cache = false to fetch from disk instead of the cache.
|
25
30
|
def content(key = nil)
|
26
|
-
|
31
|
+
!key ? (@joined ||= joined) : (@cached ||= cached)
|
27
32
|
end
|
28
33
|
|
29
34
|
# The cached content
|
data/lib/assets/util.rb
CHANGED
@@ -18,36 +18,27 @@ module Asset
|
|
18
18
|
|
19
19
|
# Load manifest
|
20
20
|
def self.load_manifest
|
21
|
-
list =
|
21
|
+
list = Dir["#{Asset.path}/{css,js}/**/*"].select{|f| File.file?(f)}.map{|f| f.gsub(Asset.path + '/', '')}
|
22
22
|
manifest = []
|
23
|
+
list.each do |file|
|
24
|
+
file =~ /(js|css)\/(.+)/
|
25
|
+
type, name = $1, $2
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
files.each do |name|
|
27
|
+
# Get the modified time of the asset
|
28
|
+
modified = mtime("#{type}/#{name}")
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# Path looks like app.js or similar
|
32
|
-
path = h ? name.keys[0] : name
|
33
|
-
|
34
|
-
# Get the modified time of the asset
|
35
|
-
modified = mtime("#{type}/#{path}")
|
30
|
+
# Loading manifest with items
|
31
|
+
manifest << ::Asset::Item.new(name, type, digest(name, modified), modified)
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
34
|
+
# Insert the css bundle
|
35
|
+
max = manifest.select{|r| r.type == 'css'}.map{|r| r.modified}.max
|
36
|
+
manifest.insert(0, ::Asset::Item.new('bundle.css', 'css', digest('bundle.css', max), max))
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
(h ? name['compress'] : true), (h ? name['bundle'] : true))
|
44
|
-
end
|
38
|
+
# Insert the js bundle
|
39
|
+
max = manifest.select{|r| r.type == 'js'}.map{|r| r.modified}.max
|
40
|
+
manifest.insert(0, ::Asset::Item.new('bundle.js', 'js', digest('bundle.js', max), max))
|
45
41
|
|
46
|
-
# Insert the bundle
|
47
|
-
manifest.insert(0, ::Asset::Item.new(
|
48
|
-
"bundle.#{type}", type,
|
49
|
-
digest("bundle.#{type}", max), max))
|
50
|
-
end
|
51
42
|
manifest
|
52
43
|
end
|
53
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fugroup Limited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- asset.gemspec
|
194
194
|
- config.ru
|
195
195
|
- lib/asset.rb
|
196
|
+
- lib/assets/filters.rb
|
196
197
|
- lib/assets/helpers.rb
|
197
198
|
- lib/assets/item.rb
|
198
199
|
- lib/assets/router.rb
|