dart_trails 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +7 -0
- data/README.md +39 -0
- data/lib/dart_trails.rb +19 -0
- data/lib/dart_trails/logging.rb +25 -0
- data/lib/dart_trails/railtie.rb +11 -0
- data/lib/dart_trails/tilt.rb +13 -0
- data/lib/dart_trails/tilt/engine.rb +119 -0
- data/lib/dart_trails/tilt/template.rb +40 -0
- data/lib/dart_trails/version.rb +5 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ff6cf3e6d9382bdf710eb6a7441c5f4ee79a5b5c
|
4
|
+
data.tar.gz: 0412ca0cbf663ffc3f9991899252c75e9434b46f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f27f17e5dc5ef70702c4784d5c0239e4c22866c6119061833489d2033d4ce8d4e805b313efc24981dda58a31c1e11d8889856e245347bdf638a61d50510d3902
|
7
|
+
data.tar.gz: bb8f42e25ecddf5ef05208e3ffd5c3b2b39fc7bd18837bfa8e9c6596dd4d7d2fb1f2e9c26e2bb59f6a35e98b364448dc2fcb241405b08d9c9ed0c052de78509f
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2013 Kelsey Judson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
DartTrails
|
2
|
+
============
|
3
|
+
|
4
|
+
DartTrails is an engine for Sprockets making use of the `dart2js` command-line
|
5
|
+
compiler which is currently very slow (so be sure to precompile assets).
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-------
|
9
|
+
|
10
|
+
Add to your `Gemfile` either ...
|
11
|
+
|
12
|
+
group :assets do
|
13
|
+
gem 'dart_trails'
|
14
|
+
end
|
15
|
+
|
16
|
+
... or using a local development tree ...
|
17
|
+
|
18
|
+
group :assets do
|
19
|
+
gem 'dart_trails', path: '/path/to/dart_trails'
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
Configuration
|
24
|
+
---------------
|
25
|
+
|
26
|
+
You may select the default command-line options by setting the attribute
|
27
|
+
`DartTrails.cli_options`. For example, to enable the command-line option
|
28
|
+
`--minify`, use ...
|
29
|
+
|
30
|
+
DartTrails.cli_options = { minify: true }
|
31
|
+
|
32
|
+
|
33
|
+
Troubleshooting
|
34
|
+
-----------------
|
35
|
+
|
36
|
+
If `.dart` assets don't seem to be compiling, you may need to clear the assets
|
37
|
+
cache from `tmp/cache/assets` as you may have an (non-compiled) cached copy of
|
38
|
+
the asset if it has been served and hasn't changed before adding the
|
39
|
+
`dart_trails` gem.
|
data/lib/dart_trails.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# https://github.com/rtomayko/tilt/blob/master/lib/tilt/template.rb
|
2
|
+
|
3
|
+
require 'dart_trails/logging'
|
4
|
+
|
5
|
+
require 'tilt'
|
6
|
+
require 'dart_trails/tilt'
|
7
|
+
require 'dart_trails/railtie'
|
8
|
+
require 'dart_trails/version'
|
9
|
+
|
10
|
+
module DartTrails
|
11
|
+
|
12
|
+
# Configuration Options
|
13
|
+
# -----------------------
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :cli_options
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module DartTrails
|
2
|
+
module Logging
|
3
|
+
|
4
|
+
def logger
|
5
|
+
@logger ||= Logger.new(STDOUT) if defined?(Logger)
|
6
|
+
end
|
7
|
+
|
8
|
+
def log(level, s)
|
9
|
+
message = format_message(level, s)
|
10
|
+
|
11
|
+
if defined?(Logger)
|
12
|
+
logger.send(level, message)
|
13
|
+
else
|
14
|
+
STDERR.puts message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def format_message(level, s)
|
21
|
+
"[DartTrails] #{level.upcase} ... #{s}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dart_trails/tilt/engine'
|
2
|
+
require 'dart_trails/tilt/template'
|
3
|
+
|
4
|
+
module DartTrails
|
5
|
+
module Tilt
|
6
|
+
|
7
|
+
# The allows Tilt.new to create a new instance of DartTilt::Template when
|
8
|
+
# it is passed a file with the extension ".dart".
|
9
|
+
#
|
10
|
+
::Tilt.register( DartTrails::Tilt::Template, 'dart' )
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module DartTrails
|
2
|
+
module Tilt
|
3
|
+
class Engine
|
4
|
+
|
5
|
+
include Logging
|
6
|
+
|
7
|
+
attr_reader :file, :options
|
8
|
+
|
9
|
+
def initialize(file, data, options = {})
|
10
|
+
@options = defaults.merge(options)
|
11
|
+
@file = fetch_file(file, data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
DartTrails
|
16
|
+
end
|
17
|
+
|
18
|
+
# This should return a string, the creation of a file is an unfortunate
|
19
|
+
# side effect (the dart2js compiler does not allow you to direct the
|
20
|
+
# compiled output to stdout). So I will need to read in the file, and
|
21
|
+
# unlink it when I am finished with it.
|
22
|
+
#
|
23
|
+
# Also keep in mind that dart2js also creates .deps and .map files which
|
24
|
+
# will need to be cleaned up.
|
25
|
+
#
|
26
|
+
def compile
|
27
|
+
redirect = { [:out, :err] => '/dev/null' }
|
28
|
+
success = system( command, *cli_options,
|
29
|
+
output_file_option, input_file,
|
30
|
+
redirect )
|
31
|
+
|
32
|
+
if success
|
33
|
+
log(:info, "Successfully compiled #{file.path}.")
|
34
|
+
read_and_unlink
|
35
|
+
else
|
36
|
+
log(:error, "Failed to compile #{file.path}.")
|
37
|
+
''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def defaults
|
44
|
+
config.cli_options || { minify: true }
|
45
|
+
end
|
46
|
+
|
47
|
+
def command
|
48
|
+
'dart2js'
|
49
|
+
end
|
50
|
+
|
51
|
+
# This isn't used with the current format of the call to Kernel#system,
|
52
|
+
# which instead passes the options as separate arguments.
|
53
|
+
#
|
54
|
+
def compile_command
|
55
|
+
"dart2js #{cli_options.join(' ')} --out=#{output_file} #{input_file}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def enabled_options
|
59
|
+
options.select { |k, v| v }
|
60
|
+
end
|
61
|
+
|
62
|
+
def cli_options
|
63
|
+
enabled_options.keys.map do |k|
|
64
|
+
cli_option(k)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def cli_option(option)
|
69
|
+
"--#{option}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def output_file
|
73
|
+
base = defined?(Rails) ? Rails.root.to_s : ''
|
74
|
+
base + '/tmp/dart_trails.dart'
|
75
|
+
end
|
76
|
+
|
77
|
+
def input_file
|
78
|
+
file.path
|
79
|
+
end
|
80
|
+
|
81
|
+
def output_file_option
|
82
|
+
"--out=#{output_file}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def fetch_file(file, data)
|
86
|
+
file ? File.new(file) : string_to_file(data)
|
87
|
+
end
|
88
|
+
|
89
|
+
# The dart2js compiler does not accept input data on stdin and expects
|
90
|
+
# an input file, so unfortunately if we receive a string, we need to
|
91
|
+
# write it to a file first.
|
92
|
+
#
|
93
|
+
def string_to_file(s)
|
94
|
+
f = Tempfile.new('dart_trails_input.dart')
|
95
|
+
f.write(s)
|
96
|
+
f.close
|
97
|
+
f
|
98
|
+
end
|
99
|
+
|
100
|
+
def read_and_unlink
|
101
|
+
files = %W{ #{output_file} #{output_file}.deps #{output_file}.map}
|
102
|
+
s = File.read(output_file)
|
103
|
+
File.unlink(*files)
|
104
|
+
|
105
|
+
strip_source_mapping(s)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Strip the JavaScript Source Map declaration to prevent the browser
|
109
|
+
# making a request for it as currently it is unlinked along with the
|
110
|
+
# other dart2js output files and I believe support for source map files
|
111
|
+
# with Sprockets is still under development.
|
112
|
+
#
|
113
|
+
def strip_source_mapping(s)
|
114
|
+
s.gsub(/\/\/[@#] sourceMappingURL=.+\.map$/, '')
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module DartTrails
|
2
|
+
module Tilt
|
3
|
+
class Template < ::Tilt::Template
|
4
|
+
|
5
|
+
attr_reader :engine
|
6
|
+
|
7
|
+
# Called once, the first time the class is initialized.
|
8
|
+
# Use this to require the underlying template library and perform any
|
9
|
+
# initial setup.
|
10
|
+
#
|
11
|
+
def initialize_engine
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.default_mime_type
|
15
|
+
'application/javascript'
|
16
|
+
end
|
17
|
+
|
18
|
+
# Implementation of #prepare is required by Tilt::Template and is called
|
19
|
+
# before #evaluate.
|
20
|
+
#
|
21
|
+
def prepare
|
22
|
+
@engine = Engine.new(file, data)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Several attributes are available.
|
26
|
+
#
|
27
|
+
# #file -> The name/path given for the original file.
|
28
|
+
# If a block passed to #new in place of a file, this will
|
29
|
+
# return nil.
|
30
|
+
# #data -> The data read from the file or passed in directly through
|
31
|
+
# a block.
|
32
|
+
# ... (see the source code) ...
|
33
|
+
#
|
34
|
+
def evaluate(scope, locals, &block)
|
35
|
+
engine.compile
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dart_trails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelsey Judson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Sprockets/Tilt engine using the dart2js compiler (slow).
|
14
|
+
email: kelseyjudson@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/dart_trails.rb
|
20
|
+
- lib/dart_trails/version.rb
|
21
|
+
- lib/dart_trails/railtie.rb
|
22
|
+
- lib/dart_trails/tilt.rb
|
23
|
+
- lib/dart_trails/logging.rb
|
24
|
+
- lib/dart_trails/tilt/engine.rb
|
25
|
+
- lib/dart_trails/tilt/template.rb
|
26
|
+
- README.md
|
27
|
+
- LICENSE
|
28
|
+
homepage: http://github.com/kelseyjudson/dart_trails
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.9.3
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 2.0.14
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Dart engine for Sprockets/Tilt.
|
52
|
+
test_files: []
|