gluey 0.2.7 → 0.3.3
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/gluey.gemspec +1 -1
- data/lib/gluey.rb +10 -1
- data/lib/gluey/base/environment.rb +34 -0
- data/lib/gluey/base/exceptions.rb +5 -0
- data/lib/gluey/base/rack_mountable.rb +87 -0
- data/lib/gluey/base/version.rb +3 -0
- data/lib/gluey/tools/local_make.rb +83 -0
- data/lib/gluey/warehouse.rb +39 -39
- data/lib/gluey/warehouse/asset_retrieving.rb +31 -0
- data/lib/gluey/workshop.rb +29 -76
- data/lib/gluey/workshop/asset_processing.rb +52 -0
- data/lib/gluey/{dependencies → workshop/dependencies}/directory.rb +0 -0
- data/lib/gluey/{dependencies → workshop/dependencies}/handlebars_bundle.rb +1 -1
- data/lib/gluey/{dependencies → workshop/dependencies}/single_file.rb +0 -0
- data/lib/gluey/{dependencies → workshop/dependencies}/texts_bundle.rb +1 -1
- data/lib/gluey/{glues → workshop/glues}/base.rb +5 -3
- data/lib/gluey/{glues → workshop/glues}/copy.rb +0 -0
- data/lib/gluey/{glues → workshop/glues}/js_script.rb +15 -16
- data/lib/gluey/{glues → workshop/glues}/js_script/handlebars_addons.rb +1 -1
- data/lib/gluey/workshop/glues/js_script/uglifier_addons.rb +19 -0
- data/lib/gluey/{glues → workshop/glues}/sass.rb +9 -7
- data/lib/gluey/{glues → workshop/glues}/script.rb +2 -2
- data/lib/gluey/{material.rb → workshop/material.rb} +11 -13
- metadata +21 -19
- data/lib/gluey/exceptions/file_not_found.rb +0 -4
- data/lib/gluey/exceptions/item_not_listed.rb +0 -4
- data/lib/gluey/tools/local_build.rb +0 -86
- data/lib/gluey/tools/tools.rb +0 -19
- data/lib/gluey/url.rb +0 -9
- data/lib/gluey/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c9c7072ee094bafc30aaff125545851b59fecc
|
4
|
+
data.tar.gz: 33d09cc9e4f936ca60e63ea9d452dc8091d0865f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86ee61effd7c25c684611a43883fada8270262cfa1eb0685c0e63f2d7e712933cf91c3b97598d3853aa3643d32e8065f16b6bd9f5f56fbb121b48c2b0f3ce978
|
7
|
+
data.tar.gz: 56846446df80b66aaacf8a61ea41f2fd87c01430238bd98122b1de2d0cee762a4e5606d4bb0a3dd6ea5dac78d91e47bb548da103e265469eac045862ec15bf33
|
data/gluey.gemspec
CHANGED
data/lib/gluey.rb
CHANGED
@@ -1,2 +1,11 @@
|
|
1
1
|
|
2
|
-
require_relative 'gluey/version'
|
2
|
+
require_relative 'gluey/base/version'
|
3
|
+
require_relative 'gluey/base/exceptions'
|
4
|
+
|
5
|
+
# environments
|
6
|
+
require_relative 'gluey/base/environment'
|
7
|
+
require_relative 'gluey/workshop'
|
8
|
+
require_relative 'gluey/warehouse'
|
9
|
+
|
10
|
+
# addons
|
11
|
+
require_relative 'gluey/base/rack_mountable'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Gluey
|
2
|
+
|
3
|
+
class Environment
|
4
|
+
|
5
|
+
attr_reader :root, :base_url, :path_prefix
|
6
|
+
attr_accessor :mark_versions
|
7
|
+
|
8
|
+
def initialize(**opts, &block)
|
9
|
+
opts = {
|
10
|
+
base_url: nil,
|
11
|
+
path_prefix: '/assets'
|
12
|
+
}.merge! opts
|
13
|
+
|
14
|
+
opts.each do |k, value|
|
15
|
+
next unless k.is_a? Symbol
|
16
|
+
instance_variable_set "@#{k}", value
|
17
|
+
end
|
18
|
+
instance_exec &block if block
|
19
|
+
|
20
|
+
root || raise('Root directory not defined!')
|
21
|
+
end
|
22
|
+
|
23
|
+
def asset_url(material, path)
|
24
|
+
"#{base_url}#{path_prefix}/#{material}/#{real_path material, path}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](material, path, mark=nil)
|
28
|
+
fetch(material, path, mark)[0]
|
29
|
+
end
|
30
|
+
alias_method :find_asset_file, :[]
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
|
3
|
+
module Gluey
|
4
|
+
class RackMountable
|
5
|
+
ALLOWED_HEADERS = %w[GET HEAD].freeze
|
6
|
+
PATH_PARSER = %r_^/(\w+)/([^\.]+)\.(?:([a-f0-9]{32})\.)?\w+$_
|
7
|
+
|
8
|
+
def initialize(env, logger)
|
9
|
+
@environment = env
|
10
|
+
@logger = logger
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
material = nil
|
15
|
+
path = nil
|
16
|
+
start_time = Time.now.to_f
|
17
|
+
time_elapsed = lambda { ((Time.now.to_f - start_time) * 1000).to_i }
|
18
|
+
|
19
|
+
unless ALLOWED_HEADERS.include? env['REQUEST_METHOD']
|
20
|
+
return method_not_allowed_response
|
21
|
+
end
|
22
|
+
|
23
|
+
# Extract the path from everything after the leading slash
|
24
|
+
_, material, path, mark = env['PATH_INFO'].to_s.match(PATH_PARSER).to_a
|
25
|
+
unless path
|
26
|
+
return bat_path_response
|
27
|
+
end
|
28
|
+
|
29
|
+
file = @environment[material, path, mark]
|
30
|
+
unless file
|
31
|
+
@logger.info "Not found glued asset #{path} (material=#{material}) - 404 (#{time_elapsed.call}ms)"
|
32
|
+
return not_found_response
|
33
|
+
end
|
34
|
+
|
35
|
+
@logger.info "Served glued asset #{path} (material=#{material}) - 200 (#{time_elapsed.call}ms)"
|
36
|
+
ok_response file, (mark && @environment.mark_versions)
|
37
|
+
|
38
|
+
rescue => e
|
39
|
+
@logger.error "Error gluying asset #{path} (material=#{material}):"
|
40
|
+
@logger.error "#{e.class.name}: #{e.message}"
|
41
|
+
raise
|
42
|
+
end
|
43
|
+
|
44
|
+
def inspect
|
45
|
+
'#<Gluey::RackMountable>'
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Returns a 200 OK response tuple
|
51
|
+
def ok_response(file, to_cache)
|
52
|
+
headers = {
|
53
|
+
'Content-Length' => File.stat(file).size,
|
54
|
+
'Content-Type' => Rack::Mime.mime_type(File.extname(file), 'text/plain')
|
55
|
+
}
|
56
|
+
if to_cache
|
57
|
+
headers['Cache-Control'] = "public, max-age=31536000"
|
58
|
+
end
|
59
|
+
|
60
|
+
[200, headers, FileBody.new(file)]
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_not_allowed_response
|
64
|
+
[405, {'Content-Type' => "text/plain", 'Content-Length' => "18"}, ['Method Not Allowed']]
|
65
|
+
end
|
66
|
+
|
67
|
+
def bat_path_response
|
68
|
+
[400, {'Content-Type' => "text/plain", 'Content-Length' => "8"}, ['Bad Path']]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns a 404 Not Found response tuple
|
72
|
+
def not_found_response
|
73
|
+
[404, {'Content-Type' => "text/plain", 'Content-Length' => "9"}, ['Not found']]
|
74
|
+
end
|
75
|
+
|
76
|
+
class FileBody < Struct.new(:file_path)
|
77
|
+
def each
|
78
|
+
File.open(file_path, 'rb') do |file|
|
79
|
+
while chunk = file.read(16384)
|
80
|
+
yield chunk
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
module Gluey::Tools
|
3
|
+
|
4
|
+
def self.make_into_assets_dir(workshop, warehouse)
|
5
|
+
made = []
|
6
|
+
|
7
|
+
warehouse.each_listed_asset workshop do |cache_file, path, material|
|
8
|
+
file = "#{warehouse.assets_path}/#{material.name}/#{path}"
|
9
|
+
next if File.exists? file
|
10
|
+
|
11
|
+
FileUtils.mkdir_p file[0..(file.rindex('/')-1)]
|
12
|
+
FileUtils.cp cache_file, file
|
13
|
+
|
14
|
+
made << file
|
15
|
+
puts "created #{file}"
|
16
|
+
end
|
17
|
+
|
18
|
+
made
|
19
|
+
end
|
20
|
+
|
21
|
+
# def self.clear_public_dir(workshop, warehouse, versions=3, public_dir='public/assets')
|
22
|
+
# public_dirs = workshop.materials.values.inject({}) do |h, m|
|
23
|
+
# h[m.name] = "#{workshop.root_path}/#{m.public_dir || public_dir}"
|
24
|
+
# h
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# # process existing files into assets
|
28
|
+
# eas_regexp = /^#{workshop.root_path}\/(.+)$/
|
29
|
+
# assets = public_dirs.values.uniq.map{|dir| Dir["#{dir}/**/*.*.*"]}.flatten.
|
30
|
+
# map{|f| Asset.try_create f[eas_regexp, 1], f}.compact
|
31
|
+
# assets = assets.inject({}){|h, asset| (h[asset.path] ||= []) << asset; h }
|
32
|
+
#
|
33
|
+
# # items not on list
|
34
|
+
# on_list = []
|
35
|
+
# warehouse.assets.each do |type, mater_assets|
|
36
|
+
# mater_assets.each do |_, real_path|
|
37
|
+
# file = "#{public_dirs[type]}/#{real_path}"
|
38
|
+
# asset = Asset.try_create file[eas_regexp, 1], f
|
39
|
+
# on_list << asset
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# on_list.map! &:path
|
43
|
+
# assets.delete_if do |path, asseets_arr|
|
44
|
+
# unless on_list.include? path
|
45
|
+
# asseets_arr.each do |some_asset|
|
46
|
+
# file = "#{workshop.root_path}/#{some_asset.orig_path}"
|
47
|
+
# File.delete file
|
48
|
+
# puts "deleted unknown #{file}"
|
49
|
+
# end
|
50
|
+
# true
|
51
|
+
# end
|
52
|
+
# false
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# # older versions
|
56
|
+
# assets.values.select{|arr| arr.length > versions}.
|
57
|
+
# map{|arr| arr.sort.slice 0..(-versions-1) }.compact.flatten.each do |old_asset|
|
58
|
+
# file = "#{workshop.root_path}/#{old_asset.orig_path}"
|
59
|
+
# File.delete file
|
60
|
+
# puts "deleted old #{file}"
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# class Asset < Struct.new(:path, :time_stamp)
|
65
|
+
#
|
66
|
+
# def self.try_create(path, file)
|
67
|
+
# path.match /^([^\.]+)\.(?:[a-f0-9]{32}\.)?(\w+)$/ do |m|
|
68
|
+
# new "#{m[1]}.#{m[2]}", File.mtime(file).to_i
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# def <=>(other)
|
73
|
+
# time_stamp <=> other.time_stamp
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# def orig_path
|
77
|
+
# ret = path.dup
|
78
|
+
# ret.insert ret.rindex('.'), ".#{time_stamp}"
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# end
|
82
|
+
|
83
|
+
end
|
data/lib/gluey/warehouse.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
require_relative '../gluey'
|
2
|
-
require_relative 'url'
|
3
|
-
require_relative 'exceptions/item_not_listed'
|
4
1
|
require 'json'
|
2
|
+
require_relative 'warehouse/asset_retrieving'
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
module Gluey
|
5
|
+
class Warehouse < Environment
|
6
|
+
include ::Gluey::AssetRetrieving
|
8
7
|
|
9
|
-
|
8
|
+
attr_reader :listing
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
unless listing
|
19
|
-
raise ::Gluey::ItemNotListed.new("Asset type #{asset_type} is not defined! (listing file problem?)")
|
10
|
+
def initialize(root, listing_path='assets/gluey_listing.json', **opts, &block)
|
11
|
+
super opts.merge!(
|
12
|
+
root: root,
|
13
|
+
listing_file: "#{root}/#{listing_path}",
|
14
|
+
), &block
|
15
|
+
@assets_path = "#{root}/#{@assets_path.chomp '/'}#{path_prefix}" if @assets_path && @assets_path[0]!='/'
|
16
|
+
read_listing
|
20
17
|
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
def read_listing
|
20
|
+
@listing = if File.exists? @listing_file
|
21
|
+
@listing = JSON.parse File.read(@listing_file) rescue nil
|
22
|
+
unless @listing.is_a? Hash
|
23
|
+
raise ::Gluey::ListingError.new("Corrupted listing file at #{@listing_file} !")
|
24
|
+
end
|
25
|
+
Hash[@listing.map{|k, v| [k.to_sym, v]}]
|
26
|
+
else
|
27
|
+
{}
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
31
|
+
def write_listing(workshop)
|
32
|
+
@listing = workshop.materials.values.inject({}) do |listing, material|
|
33
|
+
list = material.list_all_items.inject({}) do |h, path|
|
34
|
+
h[path] = workshop.real_path material.name, path
|
35
|
+
h
|
36
|
+
end
|
37
|
+
listing[material.name] = list
|
38
|
+
listing
|
39
|
+
end
|
40
|
+
File.write @listing_file, JSON.pretty_generate(@listing)
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def each_listed_asset(workshop)
|
44
|
+
@listing.each do |asset_type, list|
|
45
|
+
list.each do |path, real_path|
|
46
|
+
yield workshop[asset_type, path], real_path, workshop.material(asset_type)
|
47
|
+
end
|
45
48
|
end
|
46
|
-
listing[material.name.to_sym] = list
|
47
|
-
listing
|
48
49
|
end
|
49
|
-
File.write @listing_file, JSON.pretty_generate(@assets)
|
50
|
-
end
|
51
50
|
|
51
|
+
end
|
52
52
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Gluey
|
2
|
+
module AssetRetrieving
|
3
|
+
MARK_PARSER = %r_^[^\.]+\.(?:([a-f0-9]{32})\.)?\w+$_
|
4
|
+
|
5
|
+
def real_path(asset_type, path)
|
6
|
+
list = @listing[asset_type]
|
7
|
+
raise ::Gluey::ListingError.new("Asset type #{asset_type} is not defined!") unless list
|
8
|
+
|
9
|
+
real_path = list[path]
|
10
|
+
raise ::Gluey::ListingError.new("Unknown asset: #{path}, type=#{asset_type}!") unless real_path
|
11
|
+
|
12
|
+
real_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch(asset_type, path, mark=nil)
|
16
|
+
extant_path = real_path asset_type, path
|
17
|
+
return unless mark == extant_path.match(MARK_PARSER)[1]
|
18
|
+
|
19
|
+
file = "#{assets_path}/#{asset_type}/#{extant_path}"
|
20
|
+
file if File.exists? file
|
21
|
+
|
22
|
+
rescue ::Gluey::ListingError
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def assets_path
|
27
|
+
@assets_path ||= "#{root}/public#{path_prefix}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/gluey/workshop.rb
CHANGED
@@ -1,87 +1,40 @@
|
|
1
1
|
require 'digest'
|
2
|
-
require_relative '
|
3
|
-
require_relative '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@materials = {}
|
21
|
-
@cache = {}
|
22
|
-
end
|
23
|
-
|
24
|
-
def register_material(name, glue=::Gluey::Glues::Base, &block)
|
25
|
-
name = name.to_sym
|
26
|
-
material = ::Gluey::Material.new name, glue, self, &block
|
27
|
-
material.items << :any if material.items.empty?
|
28
|
-
@materials[name] = material
|
29
|
-
end
|
30
|
-
|
31
|
-
def fetch_file(material, path)
|
32
|
-
# check cache
|
33
|
-
cache_key = chache_asset_key material, path
|
34
|
-
file, dependencies = @cache[cache_key]
|
35
|
-
if file && File.exists?(file) && !dependencies.any?{|d| d.changed?}
|
36
|
-
return file
|
2
|
+
require_relative 'workshop/material'
|
3
|
+
require_relative 'workshop/glues/base'
|
4
|
+
require_relative 'workshop/asset_processing'
|
5
|
+
|
6
|
+
module Gluey
|
7
|
+
class Workshop < Environment
|
8
|
+
include ::Gluey::AssetProcessing
|
9
|
+
|
10
|
+
attr_reader :cache_path, :cache, :materials
|
11
|
+
|
12
|
+
def initialize(root, cache_path='tmp/gluey', **opts, &block)
|
13
|
+
super opts.merge!(
|
14
|
+
root: root,
|
15
|
+
cache_path: "#{root}/#{cache_path}",
|
16
|
+
materials: {},
|
17
|
+
cache: {}
|
18
|
+
), &block
|
19
|
+
FileUtils.mkdir_p @cache_path
|
37
20
|
end
|
38
21
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
file = "#{@tmp_path}/#{path}.#{material.asset}"
|
43
|
-
dependencies = [::Gluey::Dependencies::SingleFile.new(base_file).actualize]
|
44
|
-
# process
|
45
|
-
glue = material.glue.new self, material
|
46
|
-
FileUtils.mkdir_p file[0..(file.rindex('/')-1)]
|
47
|
-
glue.make file, base_file, dependencies
|
22
|
+
def material(name)
|
23
|
+
@materials[name.to_sym] || raise(UnregisteredMaterial.new "Unknown material #{name}.")
|
24
|
+
end
|
48
25
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
26
|
+
def register_material(name, glue=::Gluey::Glues::Base, &block)
|
27
|
+
name = name.to_sym
|
28
|
+
raise "Material #{name} already registered!" if @materials[name]
|
53
29
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
unless material.is_listed? path, file
|
58
|
-
raise ::Gluey::ItemNotListed.new("#{material.to_s} doesn't have enlisted item #{path} (file=#{file}).")
|
59
|
-
end
|
60
|
-
if digest_mark
|
61
|
-
fetch_file material.name, path
|
62
|
-
cache_key = chache_asset_key material.name, path
|
63
|
-
file, dependencies = @cache[cache_key]
|
64
|
-
digested_mark = Digest::MD5.new.digest dependencies.map(&:mark).join
|
65
|
-
"#{path}.#{Digest.hexencode digested_mark}.#{material.asset}"
|
66
|
-
else
|
67
|
-
"#{path}.#{material.asset}"
|
30
|
+
material = ::Gluey::Material.new name, glue, self, &block
|
31
|
+
material.items << :any if material.items.empty?
|
32
|
+
@materials[name] = material
|
68
33
|
end
|
69
|
-
end
|
70
34
|
|
71
|
-
|
72
|
-
|
73
|
-
yield m[1], m[2]
|
35
|
+
def get_binding
|
36
|
+
binding
|
74
37
|
end
|
75
|
-
end
|
76
38
|
|
77
|
-
def get_binding
|
78
|
-
binding
|
79
39
|
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
def chache_asset_key(material, path)
|
84
|
-
"lump:#{material}:#{path}"
|
85
|
-
end
|
86
|
-
|
87
40
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Gluey
|
2
|
+
module AssetProcessing
|
3
|
+
|
4
|
+
def fetch(material, path, mark=nil)
|
5
|
+
material = material.is_a?(::Gluey::Material) ? material : self.material(material)
|
6
|
+
raise("Unknown material #{material}!") unless material
|
7
|
+
cache_key = "lump:#{material}:#{path}"
|
8
|
+
|
9
|
+
# check cache
|
10
|
+
file, dependencies = @cache[cache_key]
|
11
|
+
if file && File.exists?(file) && !dependencies.any?{|d| d.changed?}
|
12
|
+
return file, dependencies
|
13
|
+
end
|
14
|
+
|
15
|
+
# make / remake
|
16
|
+
file, dependencies = make_asset material, path
|
17
|
+
cache[cache_key] = [file, dependencies]
|
18
|
+
return file, dependencies
|
19
|
+
end
|
20
|
+
|
21
|
+
def real_path(material_name, path)
|
22
|
+
material = self.material material_name
|
23
|
+
|
24
|
+
file = material.find_base_file path
|
25
|
+
unless material.is_listed? path, file
|
26
|
+
msg = "#{material.to_s} doesn't have enlisted item #{path} (#{file})."
|
27
|
+
raise ::Gluey::ListingError.new(msg)
|
28
|
+
end
|
29
|
+
|
30
|
+
if mark_versions
|
31
|
+
_, dependencies = fetch material, path
|
32
|
+
digested_mark = Digest::MD5.new.digest dependencies.map(&:mark).join
|
33
|
+
"#{path}.#{Digest.hexencode digested_mark}.#{material.asset_extension}"
|
34
|
+
else
|
35
|
+
"#{path}.#{material.asset_extension}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def make_asset(material, path)
|
40
|
+
# prepare for processing
|
41
|
+
base_file = material.find_base_file path
|
42
|
+
file = "#{cache_path}/#{path}.#{material.asset_extension}"
|
43
|
+
dependencies = [::Gluey::Dependencies::SingleFile.new(base_file).actualize]
|
44
|
+
# process
|
45
|
+
glue = material.glue.new self, material
|
46
|
+
FileUtils.mkdir_p file[0..(file.rindex('/')-1)]
|
47
|
+
glue.make file, base_file, dependencies
|
48
|
+
return file, dependencies
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
File without changes
|
@@ -5,7 +5,7 @@ module Gluey::Dependencies
|
|
5
5
|
class Handlebars_bundle < SingleFile
|
6
6
|
|
7
7
|
def initialize(dir, logical_path, context)
|
8
|
-
tmp_dir = "#{context.
|
8
|
+
tmp_dir = "#{context.cache_path}/.texts_bundle"
|
9
9
|
Dir.mkdir tmp_dir unless Dir.exists? tmp_dir
|
10
10
|
@cache_path = "#{tmp_dir}/#{logical_path.gsub '/', '-'}"
|
11
11
|
Dir.mkdir @cache_path unless Dir.exists? @cache_path
|
File without changes
|
@@ -12,7 +12,7 @@ module Gluey::Dependencies
|
|
12
12
|
}
|
13
13
|
|
14
14
|
def initialize(dir, logical_path, context)
|
15
|
-
tmp_dir = "#{context.
|
15
|
+
tmp_dir = "#{context.cache_path}/.texts_bundle"
|
16
16
|
Dir.mkdir tmp_dir unless Dir.exists? tmp_dir
|
17
17
|
@cache_path = "#{tmp_dir}/#{logical_path.gsub '/', '-'}"
|
18
18
|
Dir.mkdir @cache_path unless Dir.exists? @cache_path
|
@@ -22,10 +22,12 @@ module Gluey::Glues
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.load(name, *addons_names)
|
25
|
-
|
26
|
-
|
25
|
+
glue = File.expand_path("../#{name}", __FILE__)
|
26
|
+
require glue
|
27
|
+
addons_names.flatten.each{|an| require "#{glue}/#{an}_addons" }
|
28
|
+
::Gluey::Glues.const_get name.split('_').map(&:capitalize).join
|
27
29
|
rescue LoadError => e
|
28
|
-
raise e.message
|
30
|
+
raise "#{e.message}\n -- missing dependency? (are you using Gemfile?)"
|
29
31
|
end
|
30
32
|
|
31
33
|
end
|
File without changes
|
@@ -31,23 +31,22 @@ module Gluey::Glues
|
|
31
31
|
@output = "(function(){\n#{@output}\n}())"
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
34
|
+
def pre_replace_with_texts_bundle(args)
|
35
|
+
dir = File.expand_path("../#{args[1]}", @base_file)
|
36
|
+
raise "cannot find relative path #{args[1]} for script=#{@base_file}" unless dir && Dir.exists?(dir)
|
37
|
+
|
38
|
+
logical_path = dir[/(?:^#{@context.root}\/)?(.+)$/, 1]
|
39
|
+
key = "dep:txt_bundle:#{logical_path}:#{@material.name}"
|
40
|
+
hb_dep = @context.cache[key]
|
41
|
+
unless hb_dep
|
42
|
+
hb_dep = ::Gluey::Dependencies::TextsBundle.new dir, logical_path, @context
|
43
|
+
@context.cache[key] = hb_dep
|
44
|
+
end
|
45
|
+
|
46
|
+
hb_dep.actualize if hb_dep.changed?
|
47
|
+
@dependencies << hb_dep
|
48
|
+
@script.gsub! /"%#{args[0]}%"/, File.read(hb_dep.file)
|
46
49
|
end
|
47
50
|
|
48
|
-
hb_dep.actualize if hb_dep.changed?
|
49
|
-
@dependencies << hb_dep
|
50
|
-
@script.gsub! /"%#{args[0]}%"/, File.read(hb_dep.file)
|
51
51
|
end
|
52
|
-
|
53
52
|
end
|
@@ -7,7 +7,7 @@ module Gluey::Glues
|
|
7
7
|
dir = File.expand_path("../#{args[1]}", @base_file)
|
8
8
|
raise "cannot find dir containing handlebars templates for script=#{@base_file}" unless dir && Dir.exists?(dir)
|
9
9
|
|
10
|
-
logical_path = dir[/(?:^#{@context.
|
10
|
+
logical_path = dir[/(?:^#{@context.root}\/)?(.+)$/, 1]
|
11
11
|
key = "dep:hb_bundle:#{logical_path}:#{@material.name}"
|
12
12
|
hb_dep = @context.cache[key]
|
13
13
|
unless hb_dep
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uglifier'
|
2
|
+
|
3
|
+
module Gluey::Glues
|
4
|
+
class JsScript < Script
|
5
|
+
|
6
|
+
def self.set_uglifier_options(**opts)
|
7
|
+
@uglifier_options = {copyright: :none}.merge! opts
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.uglifier
|
11
|
+
@uglifier ||= ::Uglifier.new(@uglifier_options || set_uglifier_options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def process(base_file, deps)
|
15
|
+
JsScript.uglifier.compile super
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'sass'
|
2
2
|
require_relative 'script'
|
3
|
-
require_relative '../dependencies/single_file'
|
4
3
|
|
5
4
|
module Gluey::Glues
|
6
5
|
class Sass < Script
|
7
6
|
|
7
|
+
class << self
|
8
|
+
attr_accessor :engine_opts
|
9
|
+
end
|
10
|
+
self.engine_opts = {line_comments: true}
|
11
|
+
|
8
12
|
def process(base_file, deps)
|
9
|
-
opts =
|
10
|
-
syntax: @material.file_extension.to_sym,
|
13
|
+
opts = self.class.engine_opts.merge syntax: @material.file_extension.to_sym,
|
11
14
|
load_paths: [File.expand_path('..', base_file)],
|
12
|
-
cache_store: ::Sass::CacheStores::Filesystem.new("#{@context.
|
13
|
-
filename: base_file
|
14
|
-
|
15
|
-
}
|
15
|
+
cache_store: ::Sass::CacheStores::Filesystem.new("#{@context.cache_path}/.sass"),
|
16
|
+
filename: base_file
|
17
|
+
|
16
18
|
engine = ::Sass::Engine.new super(base_file, deps), opts
|
17
19
|
output = engine.render
|
18
20
|
|
@@ -64,13 +64,13 @@ module Gluey::Glues
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def get_nested_piece(file)
|
67
|
-
path = file[/(?:^#{@context.
|
67
|
+
path = file[/(?:^#{@context.root}\/)?(.+)$/, 1]
|
68
68
|
key = "script_piece:#{@material.name}:#{path}"
|
69
69
|
cache_file, dependencies = @context.cache[key]
|
70
70
|
return cache_file, dependencies if cache_file && File.exists?(cache_file) && !dependencies.any?{|dep| dep.changed?}
|
71
71
|
|
72
72
|
glue = self.class.new @context, @material
|
73
|
-
cache_dir = "#{@context.
|
73
|
+
cache_dir = "#{@context.cache_path}/.script"
|
74
74
|
Dir.mkdir cache_dir unless Dir.exists? cache_dir
|
75
75
|
cache_file = "#{cache_dir}/#{path}.#{@material.name}"
|
76
76
|
dependencies = [::Gluey::Dependencies::SingleFile.new(file).actualize]
|
@@ -1,27 +1,25 @@
|
|
1
|
-
require_relative 'exceptions/file_not_found'
|
2
1
|
|
3
2
|
class Gluey::Material
|
4
3
|
|
5
4
|
attr_reader :name, :glue, :paths, :items
|
6
|
-
attr_accessor :
|
5
|
+
attr_accessor :asset_extension, :file_extension
|
7
6
|
|
8
7
|
def initialize(name, glue, context)
|
9
8
|
@name = name.to_sym
|
10
9
|
@glue = glue
|
11
10
|
@context = context
|
12
|
-
@asset = name.to_s
|
13
|
-
@paths = []
|
14
|
-
@items = []
|
15
|
-
yield self if block_given?
|
16
|
-
@file_extension ||= @asset.dup
|
17
|
-
end
|
18
11
|
|
19
|
-
|
20
|
-
|
12
|
+
set({asset_extension: name.to_s, paths: [], items: []})
|
13
|
+
yield self if block_given?
|
14
|
+
@file_extension ||= @asset_extension.dup
|
21
15
|
end
|
22
16
|
|
23
|
-
def
|
24
|
-
|
17
|
+
def set(**opts)
|
18
|
+
allowed_options = %i(paths items asset_extension file_extension)
|
19
|
+
opts.each do |k, value|
|
20
|
+
next unless allowed_options.include? k
|
21
|
+
instance_variable_set "@#{k}", value
|
22
|
+
end
|
25
23
|
end
|
26
24
|
|
27
25
|
def is_listed?(path, file)
|
@@ -71,7 +69,7 @@ class Gluey::Material
|
|
71
69
|
private
|
72
70
|
|
73
71
|
def full_paths
|
74
|
-
@paths.map{|p| "#{@context.
|
72
|
+
@paths.map{|p| "#{@context.root}/#{p}"}
|
75
73
|
end
|
76
74
|
|
77
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gluey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- doooby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,25 +52,27 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- gluey.gemspec
|
54
54
|
- lib/gluey.rb
|
55
|
-
- lib/gluey/
|
56
|
-
- lib/gluey/
|
57
|
-
- lib/gluey/
|
58
|
-
- lib/gluey/
|
59
|
-
- lib/gluey/
|
60
|
-
- lib/gluey/exceptions/item_not_listed.rb
|
61
|
-
- lib/gluey/glues/base.rb
|
62
|
-
- lib/gluey/glues/copy.rb
|
63
|
-
- lib/gluey/glues/js_script.rb
|
64
|
-
- lib/gluey/glues/js_script/handlebars_addons.rb
|
65
|
-
- lib/gluey/glues/sass.rb
|
66
|
-
- lib/gluey/glues/script.rb
|
67
|
-
- lib/gluey/material.rb
|
68
|
-
- lib/gluey/tools/local_build.rb
|
69
|
-
- lib/gluey/tools/tools.rb
|
70
|
-
- lib/gluey/url.rb
|
71
|
-
- lib/gluey/version.rb
|
55
|
+
- lib/gluey/base/environment.rb
|
56
|
+
- lib/gluey/base/exceptions.rb
|
57
|
+
- lib/gluey/base/rack_mountable.rb
|
58
|
+
- lib/gluey/base/version.rb
|
59
|
+
- lib/gluey/tools/local_make.rb
|
72
60
|
- lib/gluey/warehouse.rb
|
61
|
+
- lib/gluey/warehouse/asset_retrieving.rb
|
73
62
|
- lib/gluey/workshop.rb
|
63
|
+
- lib/gluey/workshop/asset_processing.rb
|
64
|
+
- lib/gluey/workshop/dependencies/directory.rb
|
65
|
+
- lib/gluey/workshop/dependencies/handlebars_bundle.rb
|
66
|
+
- lib/gluey/workshop/dependencies/single_file.rb
|
67
|
+
- lib/gluey/workshop/dependencies/texts_bundle.rb
|
68
|
+
- lib/gluey/workshop/glues/base.rb
|
69
|
+
- lib/gluey/workshop/glues/copy.rb
|
70
|
+
- lib/gluey/workshop/glues/js_script.rb
|
71
|
+
- lib/gluey/workshop/glues/js_script/handlebars_addons.rb
|
72
|
+
- lib/gluey/workshop/glues/js_script/uglifier_addons.rb
|
73
|
+
- lib/gluey/workshop/glues/sass.rb
|
74
|
+
- lib/gluey/workshop/glues/script.rb
|
75
|
+
- lib/gluey/workshop/material.rb
|
74
76
|
homepage:
|
75
77
|
licenses:
|
76
78
|
- MIT
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require_relative 'tools'
|
2
|
-
|
3
|
-
module Gluey::Tools
|
4
|
-
|
5
|
-
def self.build_into_public_dir(workshop, warehouse, public_dir='public/assets', **builders)
|
6
|
-
public_dirs = workshop.materials.values.inject({}) do |h, m|
|
7
|
-
h[m.name] = "#{workshop.root_path}/#{m.public_dir || public_dir}"
|
8
|
-
h
|
9
|
-
end
|
10
|
-
|
11
|
-
built = []
|
12
|
-
move_it = -> (cache_file, file) { FileUtils.mv cache_file, file }
|
13
|
-
self.each_asset_file workshop, warehouse do |cache_file, type, path|
|
14
|
-
file = "#{public_dirs[type]}/#{path}"
|
15
|
-
next if File.exists? file
|
16
|
-
FileUtils.mkdir_p file[0..(file.rindex('/')-1)]
|
17
|
-
(builders[type] || move_it)[cache_file, file]
|
18
|
-
built << file
|
19
|
-
puts "created #{file}"
|
20
|
-
end
|
21
|
-
return built
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.clear_public_dir(workshop, warehouse, versions=2, public_dir='public/assets')
|
25
|
-
public_dirs = workshop.materials.values.inject({}) do |h, m|
|
26
|
-
h[m.name] = "#{workshop.root_path}/#{m.public_dir || public_dir}"
|
27
|
-
h
|
28
|
-
end
|
29
|
-
|
30
|
-
# process existing files into assets
|
31
|
-
eas_regexp = /^#{workshop.root_path}\/(.+)$/
|
32
|
-
assets = public_dirs.values.uniq.map{|dir| Dir["#{dir}/**/*.*.*"]}.flatten.
|
33
|
-
map{|f| Asset.try_create f[eas_regexp, 1]}.compact
|
34
|
-
assets = assets.inject({}){|h, asset| (h[asset.path] ||= []) << asset; h }
|
35
|
-
|
36
|
-
# items not on list
|
37
|
-
on_list = []
|
38
|
-
warehouse.assets.each do |type, mater_assets|
|
39
|
-
mater_assets.each do |_, real_path|
|
40
|
-
file = "#{public_dirs[type]}/#{real_path}"
|
41
|
-
asset = Asset.try_create file[eas_regexp, 1]
|
42
|
-
on_list << asset
|
43
|
-
end
|
44
|
-
end
|
45
|
-
on_list.map! &:path
|
46
|
-
assets.delete_if do |path, asseets_arr|
|
47
|
-
unless on_list.include? path
|
48
|
-
asseets_arr.each do |some_asset|
|
49
|
-
file = "#{workshop.root_path}/#{some_asset.orig_path}"
|
50
|
-
File.delete file
|
51
|
-
puts "deleted unknown #{file}"
|
52
|
-
end
|
53
|
-
true
|
54
|
-
end
|
55
|
-
false
|
56
|
-
end
|
57
|
-
|
58
|
-
# older versions
|
59
|
-
assets.values.select{|arr| arr.length > versions}.
|
60
|
-
map{|arr| arr.sort.slice 0..(-versions-1) }.compact.flatten.each do |old_asset|
|
61
|
-
file = "#{workshop.root_path}/#{old_asset.orig_path}"
|
62
|
-
File.delete file
|
63
|
-
puts "deleted old #{file}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class Asset < Struct.new(:path, :time_stamp)
|
68
|
-
|
69
|
-
def self.try_create(file)
|
70
|
-
file.match /^([^\.]+)\.(\d+)\.(\w+)$/ do |m|
|
71
|
-
new "#{m[1]}.#{m[3]}", m[2]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def <=>(other)
|
76
|
-
time_stamp <=> other.time_stamp
|
77
|
-
end
|
78
|
-
|
79
|
-
def orig_path
|
80
|
-
ret = path.dup
|
81
|
-
ret.insert ret.rindex('.'), ".#{time_stamp}"
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
data/lib/gluey/tools/tools.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'gluey/warehouse'
|
2
|
-
|
3
|
-
module Gluey::Tools
|
4
|
-
|
5
|
-
def self.each_asset_file(workshop, warehouse)
|
6
|
-
warehouse.assets.each do |type, assets|
|
7
|
-
assets.each do |path, real_path|
|
8
|
-
cache_file = workshop.fetch_file type, path
|
9
|
-
yield cache_file, type, real_path
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.create_uglifier_builder(**opts)
|
15
|
-
require 'uglifier'
|
16
|
-
->(a, b){File.write b, ::Uglifier.new(opts.merge! copyright: :none).compile(File.read a)}
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
data/lib/gluey/url.rb
DELETED
data/lib/gluey/version.rb
DELETED