fuse 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fuse.rb +17 -20
- data/lib/fuse/document.rb +1 -3
- data/lib/fuse/document/asset.rb +18 -14
- data/lib/fuse/document/asset/font.rb +16 -6
- data/lib/fuse/document/asset/has_dependents.rb +3 -3
- data/lib/fuse/document/asset/java_script.rb +10 -0
- data/lib/fuse/document/asset/style_sheet.rb +2 -0
- data/lib/fuse/document/asset_collection.rb +6 -3
- data/lib/fuse/document/asset_types.rb +2 -11
- data/lib/fuse/exceptions.rb +9 -1
- data/lib/fuse/main.rb +7 -4
- data/lib/fuse/server.rb +3 -0
- metadata +2 -2
data/lib/fuse.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'thin'
|
3
|
-
|
4
1
|
module Fuse
|
5
2
|
|
6
|
-
VERSION = '0.1.
|
3
|
+
VERSION = '0.1.9'
|
7
4
|
|
8
5
|
LOG_COLOURS = {
|
9
6
|
info: 6, # cyan
|
@@ -12,25 +9,25 @@ module Fuse
|
|
12
9
|
notice: 3 # yellow
|
13
10
|
}
|
14
11
|
|
15
|
-
|
16
|
-
@root ||= File.expand_path File.dirname(__FILE__)
|
17
|
-
end
|
12
|
+
class << self
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def root
|
15
|
+
@root ||= File.expand_path File.dirname(__FILE__)
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
def log_file=(file)
|
19
|
+
@log_file = file
|
20
|
+
end
|
21
|
+
|
22
|
+
def log_file
|
23
|
+
@log_file ||= $stderr
|
24
|
+
end
|
25
|
+
|
26
|
+
def log(message, type = nil)
|
27
|
+
colour = 30 + (LOG_COLOURS[type] || LOG_COLOURS[:info])
|
28
|
+
log_file.puts "\x1b[#{colour}m#{message}\x1b[0m"
|
29
|
+
end
|
26
30
|
|
27
|
-
def self.log(message, type = nil)
|
28
|
-
m = "\x1b["
|
29
|
-
m << (30 + (LOG_COLOURS[type] || LOG_COLOURS[:info])).to_s
|
30
|
-
m << 'm'
|
31
|
-
m << message
|
32
|
-
m << "\x1b[0m"
|
33
|
-
log_file.puts m
|
34
31
|
end
|
35
32
|
|
36
33
|
end
|
data/lib/fuse/document.rb
CHANGED
@@ -69,9 +69,7 @@ class Fuse::Document
|
|
69
69
|
fonts.values.each do |formats|
|
70
70
|
first = formats.values.first
|
71
71
|
font_css << '@font-face{'
|
72
|
-
font_css << 'font
|
73
|
-
font_css << 'font-weight: %s;' % first.weight
|
74
|
-
font_css << 'font-style: %s;' % first.style
|
72
|
+
font_css << first.variant.map{ |k, v| 'font-%s: "%s";' % [k, v] }.join
|
75
73
|
font_css << 'src: url("%s");' % formats[:eot].relative_path if formats[:eot] && !@options[:embed_assets]
|
76
74
|
css_formats = []
|
77
75
|
Fuse::Document::Asset::Font::CSS_FORMATS.each do |css_format|
|
data/lib/fuse/document/asset.rb
CHANGED
@@ -2,20 +2,24 @@ require 'base64'
|
|
2
2
|
|
3
3
|
class Fuse::Document::Asset
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def [](dir)
|
8
|
+
assets = Fuse::Document::AssetCollection.new
|
9
|
+
Dir[File.join dir, '**/*.*'].each do |full_path|
|
10
|
+
asset = self.for(full_path[dir.length..-1], dir)
|
11
|
+
assets << asset if asset
|
12
|
+
end
|
13
|
+
assets
|
14
|
+
end
|
15
|
+
|
16
|
+
def for(path, root = Dir.pwd)
|
17
|
+
full_path = File.join root, path
|
18
|
+
return unless File.exists? full_path
|
19
|
+
type = TYPES[(File.extname(path)[1..-1] || '').to_sym]
|
20
|
+
(@cache ||= {})[File.expand_path full_path] ||= type.new(path, root) if type
|
10
21
|
end
|
11
|
-
assets
|
12
|
-
end
|
13
22
|
|
14
|
-
def self.for(path, root = Dir.pwd)
|
15
|
-
full_path = File.join root, path
|
16
|
-
return unless File.exists? full_path
|
17
|
-
type = TYPES[(File.extname(path)[1..-1] || '').to_sym]
|
18
|
-
(@cache ||= {})[File.expand_path full_path] ||= type.new(path, root) if type
|
19
23
|
end
|
20
24
|
|
21
25
|
attr_reader :path
|
@@ -58,10 +62,10 @@ class Fuse::Document::Asset
|
|
58
62
|
@type ||= Rack::Mime.mime_type('.' + extension)
|
59
63
|
end
|
60
64
|
|
61
|
-
def to_datauri(
|
65
|
+
def to_datauri(compressed = false)
|
62
66
|
'data:%s;base64,%s' % [
|
63
67
|
type,
|
64
|
-
Base64.strict_encode64(
|
68
|
+
Base64.strict_encode64(compressed && respond_to?(:compress) ? compress : raw)
|
65
69
|
]
|
66
70
|
end
|
67
71
|
|
@@ -1,19 +1,24 @@
|
|
1
1
|
class Fuse::Document::Asset
|
2
2
|
class Font < self
|
3
|
+
|
3
4
|
CSS_FORMATS = [
|
4
5
|
{ extension: :woff, format: 'woff' },
|
5
6
|
{ extension: :ttf, format: 'truetype' },
|
6
7
|
{ extension: :otf, format: 'opentype' }
|
7
8
|
]
|
9
|
+
|
8
10
|
MIME_TYPES = {
|
9
|
-
otf:
|
10
|
-
ttf:
|
11
|
+
otf: 'application/x-font-opentype',
|
12
|
+
ttf: 'application/x-font-truetype',
|
11
13
|
woff: 'application/x-font-woff'
|
12
14
|
}
|
15
|
+
|
13
16
|
VARIANT_PATTERN = %r`([^/]+?)(?:[-_ ](normal|bold|bolder|lighter|[1-9]00))?(?:[-_ ](normal|italic|oblique))?\.[a-z]+$`
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
|
18
|
+
[:family, :weight, :style].each do |attr|
|
19
|
+
define_method(attr) { variant[attr] }
|
20
|
+
end
|
21
|
+
|
17
22
|
def variant
|
18
23
|
@variant ||= begin
|
19
24
|
match = VARIANT_PATTERN.match(path)
|
@@ -24,9 +29,14 @@ class Fuse::Document::Asset
|
|
24
29
|
}
|
25
30
|
end
|
26
31
|
end
|
27
|
-
|
32
|
+
|
33
|
+
def face
|
34
|
+
@face ||= [family, weight, style].join('-')
|
35
|
+
end
|
36
|
+
|
28
37
|
def type
|
29
38
|
MIME_TYPES[extension.to_sym] || super
|
30
39
|
end
|
40
|
+
|
31
41
|
end
|
32
42
|
end
|
@@ -4,7 +4,7 @@ module Fuse::Document::Asset::HasDependents
|
|
4
4
|
REQUIRE_PATTERN = %r`^\s*(?:\*|//)=\s+(require|require_glob)\s+(.+?)\s*$`
|
5
5
|
|
6
6
|
def dependents
|
7
|
-
|
7
|
+
collection = Fuse::Document::AssetCollection.new
|
8
8
|
local_root = File.dirname(full_path)
|
9
9
|
if (comments = raw[COMMENT_PATTERN])
|
10
10
|
comments.lines.each do |line|
|
@@ -21,11 +21,11 @@ module Fuse::Document::Asset::HasDependents
|
|
21
21
|
end.reject do |p|
|
22
22
|
p.nil?
|
23
23
|
end.each do |p|
|
24
|
-
|
24
|
+
collection << p
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
collection
|
30
30
|
end
|
31
31
|
end
|
@@ -1,8 +1,14 @@
|
|
1
|
+
require 'coffee-script'
|
2
|
+
require 'uglifier'
|
3
|
+
|
1
4
|
class Fuse::Document::Asset
|
2
5
|
class JavaScript < self
|
6
|
+
|
3
7
|
EMBED_WITH = 'script'
|
4
8
|
JOIN_WITH = ';'
|
9
|
+
|
5
10
|
include HasDependents
|
11
|
+
|
6
12
|
def reference_with
|
7
13
|
{
|
8
14
|
tag_name: 'script',
|
@@ -12,13 +18,16 @@ class Fuse::Document::Asset
|
|
12
18
|
}
|
13
19
|
}
|
14
20
|
end
|
21
|
+
|
15
22
|
def compress
|
16
23
|
original = filtered
|
17
24
|
compressed = Uglifier.compile original
|
18
25
|
Fuse.log "Uglifier: Compressed #{path} from #{original.bytesize} bytes to #{compressed.bytesize} bytes", :success
|
19
26
|
compressed
|
20
27
|
end
|
28
|
+
|
21
29
|
def type; 'text/javascript' end
|
30
|
+
|
22
31
|
class Coffee < self
|
23
32
|
def filter
|
24
33
|
original = raw
|
@@ -27,6 +36,7 @@ class Fuse::Document::Asset
|
|
27
36
|
compiled
|
28
37
|
end
|
29
38
|
end
|
39
|
+
|
30
40
|
end
|
31
41
|
|
32
42
|
end
|
@@ -24,9 +24,12 @@ class Fuse::Document::AssetCollection < Array
|
|
24
24
|
self
|
25
25
|
end
|
26
26
|
|
27
|
-
def push_with_dependents(asset)
|
28
|
-
|
29
|
-
asset.dependents.each
|
27
|
+
def push_with_dependents(asset, pushed = [])
|
28
|
+
pushed << asset
|
29
|
+
asset.dependents.each do |dependent|
|
30
|
+
raise Fuse::Exception::CircularDependency.new(asset, dependent) if pushed.include?(dependent)
|
31
|
+
push_with_dependents dependent, pushed
|
32
|
+
end
|
30
33
|
self << asset
|
31
34
|
end
|
32
35
|
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'sass'
|
2
|
-
require 'coffee-script'
|
3
|
-
require 'uglifier'
|
4
|
-
|
5
1
|
class Fuse::Document::Asset
|
6
2
|
|
7
3
|
class Image < self
|
@@ -13,13 +9,8 @@ class Fuse::Document::Asset
|
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
class Xsl < self
|
20
|
-
end
|
21
|
-
|
22
|
-
class Html < self
|
12
|
+
def self.const_missing(name)
|
13
|
+
(@anonymous_subclasses ||= {})[name] ||= Class.new(self)
|
23
14
|
end
|
24
15
|
|
25
16
|
TYPES = {
|
data/lib/fuse/exceptions.rb
CHANGED
@@ -16,10 +16,18 @@ class Fuse::Exception < ::RuntimeError
|
|
16
16
|
end
|
17
17
|
def message; 'Couldn\'t determine source document. Please specify one with --source.' end
|
18
18
|
end
|
19
|
-
class XslMissing
|
19
|
+
class XslMissing < self
|
20
20
|
def message
|
21
21
|
'Couldn\'t locate an XSL stylesheet to transform the source document. Please specify one with --xsl.'
|
22
22
|
end
|
23
23
|
end
|
24
|
+
class CircularDependency < self
|
25
|
+
def initialize(offender, dependent)
|
26
|
+
@offender, @dependent = offender, dependent
|
27
|
+
end
|
28
|
+
def message
|
29
|
+
"Found circular dependency as #{@offender.path} depends upon #{@dependent.path}"
|
30
|
+
end
|
31
|
+
end
|
24
32
|
def message; end
|
25
33
|
end
|
data/lib/fuse/main.rb
CHANGED
@@ -23,7 +23,9 @@ module Fuse
|
|
23
23
|
SUMMARY_WIDTH = 30
|
24
24
|
SUMMARY_INDENT = 4
|
25
25
|
|
26
|
-
|
26
|
+
class << self
|
27
|
+
|
28
|
+
def main
|
27
29
|
|
28
30
|
options = {}
|
29
31
|
|
@@ -148,7 +150,7 @@ Options:
|
|
148
150
|
|
149
151
|
private
|
150
152
|
|
151
|
-
def
|
153
|
+
def merge_defaults(options)
|
152
154
|
if (defaults = DEFAULTS[(ARGV[0] || '').to_sym])
|
153
155
|
defaults.merge(DEFAULTS[:common]).merge(options)
|
154
156
|
else
|
@@ -156,12 +158,13 @@ Options:
|
|
156
158
|
end
|
157
159
|
end
|
158
160
|
|
159
|
-
def
|
161
|
+
def wrap(text, width = 80 - SUMMARY_WIDTH)
|
160
162
|
text.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n#{' ' * (SUMMARY_WIDTH + SUMMARY_INDENT + 1)}").strip
|
161
163
|
end
|
162
164
|
|
163
|
-
def
|
165
|
+
def summary(opts)
|
164
166
|
abort opts.summarize([], SUMMARY_WIDTH, SUMMARY_WIDTH - 1, ' ' * SUMMARY_INDENT).join
|
165
167
|
end
|
166
168
|
|
169
|
+
end
|
167
170
|
end
|
data/lib/fuse/server.rb
CHANGED
@@ -26,9 +26,11 @@ class Fuse::Server
|
|
26
26
|
result = doc.to_s
|
27
27
|
log env, "Using #{doc.xsl_path} for transformation" if doc.xsl_path
|
28
28
|
log env, "Rendered #{doc.source_path} (#{result.length} bytes)", :success
|
29
|
+
|
29
30
|
rescue Fuse::Exception::SourceUnknown::TooManySources
|
30
31
|
result = render_list($!.options, $!.option_name, request)
|
31
32
|
log env, 'Multiple source document options', :notice
|
33
|
+
|
32
34
|
rescue Fuse::Exception
|
33
35
|
if $!.message
|
34
36
|
result = render_error($!.message)
|
@@ -36,6 +38,7 @@ class Fuse::Server
|
|
36
38
|
else
|
37
39
|
raise
|
38
40
|
end
|
41
|
+
|
39
42
|
end if request.path == '/'
|
40
43
|
|
41
44
|
if result.nil?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|