processit 1.0.1
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.
- data/Gemfile +8 -0
- data/README +16 -0
- data/README.markdown +16 -0
- data/bin/processit +49 -0
- data/lib/processit.rb +27 -0
- data/lib/processit/base.rb +105 -0
- data/lib/processit/builder.rb +105 -0
- data/lib/processit/context.rb +236 -0
- data/lib/processit/processor/charset_normalizer.rb +41 -0
- data/lib/processit/processor/ejs_template.rb +37 -0
- data/lib/processit/processor/jsmin_template.rb +32 -0
- data/lib/processit/processor/jst_processor.rb +33 -0
- data/lib/processit/processor/safety_colons.rb +28 -0
- data/lib/processit/processors.rb +56 -0
- data/lib/processit/setup.rb +17 -0
- data/lib/processit/templates/default/config.rb +13 -0
- data/lib/processit/templates/default/src/css/bootstrap.css +4883 -0
- data/lib/processit/templates/default/src/css/bootstrap.min.css +729 -0
- data/lib/processit/templates/default/src/css/main.css +5 -0
- data/lib/processit/templates/default/src/css/variables.css +9 -0
- data/lib/processit/templates/default/src/img/glyphicons-halflings-white.png +0 -0
- data/lib/processit/templates/default/src/img/glyphicons-halflings.png +0 -0
- data/lib/processit/templates/default/src/js/application.js +7 -0
- data/lib/processit/templates/default/src/js/include.js +3 -0
- data/lib/processit/templates/default/src/js/lib/bootstrap.js +1835 -0
- data/lib/processit/templates/default/src/js/lib/bootstrap.min.js +7 -0
- data/lib/processit/templates/default/src/js/lib/jquery-1.7.2.js +9404 -0
- data/lib/processit/templates/default/src/js/lib/jquery-1.7.2.min.js +4 -0
- data/lib/processit/templates/default/src/pages/index.haml +19 -0
- data/lib/processit/utils.rb +69 -0
- data/lib/processit/version.rb +3 -0
- metadata +138 -0
data/Gemfile
ADDED
data/README
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<h1>ProcessMe</h1>
|
|
2
|
+
|
|
3
|
+
<h2>Resources</h2>
|
|
4
|
+
|
|
5
|
+
* [ProcessMe Homepage](http://process-me.org/)
|
|
6
|
+
* [Installing ProcessMe](http://process-me.org/install/)
|
|
7
|
+
* [ProcessMe Reference](http://process-me.org/install/reference/)
|
|
8
|
+
|
|
9
|
+
<h2>Author</h2>
|
|
10
|
+
ProcessMe is written by [Adam Scherer][adam@annconia.com].<br>
|
|
11
|
+
Adam is a Software Architect who likes everything simple.
|
|
12
|
+
|
|
13
|
+
<h2>License</h2>
|
|
14
|
+
Copyright (c) 2012 Adam Scherer<br>
|
|
15
|
+
All Rights Reserved.<br>
|
|
16
|
+
Released under a [slightly modified MIT License][license].
|
data/README.markdown
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# ProcessIt
|
|
2
|
+
|
|
3
|
+
## Resources
|
|
4
|
+
|
|
5
|
+
* [ProcessMe Homepage](http://process-it.org/)
|
|
6
|
+
* [Installing ProcessMe](http://process-it.org/install/)
|
|
7
|
+
* [ProcessMe Reference](http://process-it.org/install/reference/)
|
|
8
|
+
|
|
9
|
+
## Author
|
|
10
|
+
ProcessMe is written by [Adam Scherer][adam@annconia.com].<br>
|
|
11
|
+
Adam is a Software Architect who likes everything simple.
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
Copyright (c) 2012 Adam Scherer<br>
|
|
15
|
+
All Rights Reserved.<br>
|
|
16
|
+
Released under a [slightly modified MIT License][license].
|
data/bin/processit
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'processit'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'shellwords'
|
|
6
|
+
|
|
7
|
+
builder = ProcessIt::Builder.new
|
|
8
|
+
|
|
9
|
+
OptionParser.new do |opts|
|
|
10
|
+
opts.summary_width = 28
|
|
11
|
+
opts.banner = "Usage: processit [options]"
|
|
12
|
+
|
|
13
|
+
def opts.show_usage
|
|
14
|
+
puts self
|
|
15
|
+
exit 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
opts.on("-c", "--compile", "Compile the entire source structure") do |name|
|
|
19
|
+
builder.build
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
opts.on("-w", "--watch", "Perform an initial compile and then monitor for changes to compile automatically") do |directory|
|
|
23
|
+
builder.watch
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
opts.on("-n PROJECT_NAME", "--create PROJECT_NAME", "Copy the project template into PROJECT_NAME") do |name|
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
opts.on_tail("-h", "--help", "Shows this help message") do
|
|
31
|
+
opts.show_usage
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
opts.on_tail("-v", "--version", "Shows version") do
|
|
35
|
+
puts ProcessIt::VERSION
|
|
36
|
+
exit
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
opts.show_usage if ARGV.empty?
|
|
40
|
+
|
|
41
|
+
begin
|
|
42
|
+
opts.order(ARGV) do |filename|
|
|
43
|
+
filenames << File.expand_path(filename)
|
|
44
|
+
end
|
|
45
|
+
rescue OptionParser::ParseError => e
|
|
46
|
+
opts.warn e.message
|
|
47
|
+
opts.show_usage
|
|
48
|
+
end
|
|
49
|
+
end
|
data/lib/processit.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'processit/version'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module ProcessIt
|
|
5
|
+
|
|
6
|
+
autoload :EjsTemplate, "processit/processor/ejs_template"
|
|
7
|
+
autoload :JstProcessor, "processit/processor/jst_processor"
|
|
8
|
+
autoload :JsMinTemplate, "processit/processor/jsmin_template"
|
|
9
|
+
autoload :CharsetNormalizer, "processit/processor/charset_normalizer"
|
|
10
|
+
autoload :SafetyColons, "processit/processor/safety_colons"
|
|
11
|
+
autoload :Utils, "processit/utils"
|
|
12
|
+
|
|
13
|
+
require 'processit/processors'
|
|
14
|
+
require 'processit/builder'
|
|
15
|
+
require 'tilt'
|
|
16
|
+
require 'haml'
|
|
17
|
+
require 'yaml'
|
|
18
|
+
|
|
19
|
+
Processors.instance.register_processor '.js', 'js', [Tilt::ERBTemplate, SafetyColons, JsMinTemplate]
|
|
20
|
+
Processors.instance.register_processor '.jst', 'js', [Tilt::ERBTemplate, EjsTemplate]
|
|
21
|
+
Processors.instance.register_processor '.haml', 'html', [Tilt::ERBTemplate, Tilt::HamlTemplate]
|
|
22
|
+
Processors.instance.register_processor '.html', 'html', [Tilt::ERBTemplate]
|
|
23
|
+
Processors.instance.register_processor '.scss', 'css', [Tilt::ERBTemplate, Tilt::ScssTemplate]
|
|
24
|
+
Processors.instance.register_processor '.sass', 'css', [Tilt::ERBTemplate, Tilt::SassTemplate]
|
|
25
|
+
Processors.instance.register_processor '.css', 'css', [Tilt::ERBTemplate, CharsetNormalizer]
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
module ProcessIt
|
|
2
|
+
class Base
|
|
3
|
+
|
|
4
|
+
include StaticMatic::RenderMixin
|
|
5
|
+
include StaticMatic::BuildMixin
|
|
6
|
+
include StaticMatic::SetupMixin
|
|
7
|
+
include StaticMatic::HelpersMixin
|
|
8
|
+
include StaticMatic::ServerMixin
|
|
9
|
+
include StaticMatic::RescueMixin
|
|
10
|
+
|
|
11
|
+
attr_accessor :configuration
|
|
12
|
+
attr_reader :current_page, :src_dir, :site_dir
|
|
13
|
+
|
|
14
|
+
def current_file
|
|
15
|
+
@current_file_stack[0] || ""
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def initialize(base_dir, configuration = Configuration.new)
|
|
19
|
+
@configuration = configuration
|
|
20
|
+
@current_page = nil
|
|
21
|
+
@current_file_stack = []
|
|
22
|
+
@base_dir = base_dir
|
|
23
|
+
@src_dir = File.join(@base_dir, "src")
|
|
24
|
+
@site_dir = File.join(@base_dir, "site")
|
|
25
|
+
|
|
26
|
+
if File.exists?(File.join(@src_dir, "layouts", "application.haml"))
|
|
27
|
+
puts "DEPRECATION: layouts/application.haml will be renamed to layouts/default.haml in 0.12.0"
|
|
28
|
+
@default_layout = "application"
|
|
29
|
+
else
|
|
30
|
+
@default_layout = "default"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
@scope = Object.new
|
|
34
|
+
@scope.instance_variable_set("@staticmatic", self)
|
|
35
|
+
|
|
36
|
+
load_configuration
|
|
37
|
+
configure_compass
|
|
38
|
+
|
|
39
|
+
load_helpers
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def load_configuration
|
|
43
|
+
configuration = StaticMatic::Configuration.new
|
|
44
|
+
config_file = File.join(@base_dir, "config", "site.rb")
|
|
45
|
+
|
|
46
|
+
if !File.exists?(config_file)
|
|
47
|
+
config_file = File.join(@base_dir, "src", "configuration.rb")
|
|
48
|
+
|
|
49
|
+
if File.exists?(config_file)
|
|
50
|
+
puts "DEPRECATION: #{@base_dir}/src/configuration.rb will be moved to #{@base_dir}/config/site.rb in 0.12.0"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if File.exists?(config_file)
|
|
55
|
+
config = File.read(config_file)
|
|
56
|
+
eval(config)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
@configuration = configuration
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def base_dir
|
|
63
|
+
@base_dir
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def run(command)
|
|
67
|
+
puts "Site root is: #{@base_dir}"
|
|
68
|
+
|
|
69
|
+
if %w(build setup preview).include?(command)
|
|
70
|
+
send(command)
|
|
71
|
+
else
|
|
72
|
+
puts "#{command} is not a valid StaticMatic command"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# TODO: DRY this _exists? section up
|
|
77
|
+
def template_exists?(name, dir = '')
|
|
78
|
+
File.exists?(File.join(@src_dir, 'pages', dir, "#{name}.haml")) || File.exists?(File.join(@src_dir, 'stylesheets', "#{name}.sass")) || File.exists?(File.join(@src_dir, 'stylesheets', "#{name}.scss"))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def layout_exists?(name)
|
|
82
|
+
File.exists? full_layout_path(name)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def template_directory?(path)
|
|
86
|
+
File.directory?(File.join(@src_dir, 'pages', path))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def full_layout_path(name)
|
|
90
|
+
File.join(@src_dir, "layouts", "#{name}.haml")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def configure_compass
|
|
94
|
+
Compass.configuration.project_path = @base_dir
|
|
95
|
+
|
|
96
|
+
compass_config_path = File.join(@base_dir, "config", "compass.rb")
|
|
97
|
+
|
|
98
|
+
if File.exists?(compass_config_path)
|
|
99
|
+
Compass.add_configuration(compass_config_path)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
configuration.sass_options.merge!(Compass.configuration.to_sass_engine_options)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'processit/utils'
|
|
2
|
+
require 'processit/processors'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
module ProcessIt
|
|
6
|
+
class Builder
|
|
7
|
+
|
|
8
|
+
def initialize(root = ".")
|
|
9
|
+
@base_dir = Dir.pwd
|
|
10
|
+
@src_dir = File.join(@base_dir, "src")
|
|
11
|
+
@site_dir = File.join(@base_dir, "site")
|
|
12
|
+
@html_src_dir = File.join(@src_dir, "pages")
|
|
13
|
+
|
|
14
|
+
@config = YAML.load_file("#{@src_dir}/data/data.yml")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def watch
|
|
18
|
+
puts ">>> ProcessMe is watching for changes. Press Ctrl-C to Stop."
|
|
19
|
+
|
|
20
|
+
require 'fssm'
|
|
21
|
+
begin
|
|
22
|
+
FSSM.monitor do |monitor|
|
|
23
|
+
monitor.path @src_dir do |path|
|
|
24
|
+
path.create do |base, relative|
|
|
25
|
+
build
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
path.update do |base, relative|
|
|
29
|
+
build
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
path.delete do |base, relative|
|
|
33
|
+
build
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def build
|
|
41
|
+
puts ">>> ProcessIt is building your site."
|
|
42
|
+
Dir["#{@src_dir}/**/*"].each do |path|
|
|
43
|
+
next if File.basename(path) =~ /^\_/ or File.directory?(path) # skip partials and directories
|
|
44
|
+
|
|
45
|
+
save_page(path, evaluate(path))
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def evaluate(path, options = {})
|
|
50
|
+
ext = File.extname(path)
|
|
51
|
+
path = File.absolute_path(path, @src_dir)
|
|
52
|
+
result = ProcessIt::Utils.read_unicode(path)
|
|
53
|
+
Processors.instance.processor(ext)["klasses"].each do |processor|
|
|
54
|
+
begin
|
|
55
|
+
template = processor.new(path) { result }
|
|
56
|
+
result = template.render(self, @config)
|
|
57
|
+
rescue Exception => e
|
|
58
|
+
puts e
|
|
59
|
+
raise
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
result
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def cms()
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def copy_file(from, to)
|
|
71
|
+
FileUtils.cp(from, to)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def save_page(path, content)
|
|
75
|
+
ext = File.extname(path)
|
|
76
|
+
file_dir, file_name = File.split(path)
|
|
77
|
+
relative_name = path.sub(/^#{@src_dir}/, '')
|
|
78
|
+
relative_name.chomp!(ext)
|
|
79
|
+
output_ext = Processors.instance.processor(ext)["output_ext"]
|
|
80
|
+
if (output_ext)
|
|
81
|
+
generate_site_file(relative_name, output_ext, content)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def generate_site_file(relative_name, extension, content)
|
|
86
|
+
|
|
87
|
+
path = File.join(@site_dir, "#{relative_name}.#{extension}")
|
|
88
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
89
|
+
File.open(path, 'w+') do |f|
|
|
90
|
+
f << content
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
puts "created #{path}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Returns a raw template name from a source file path:
|
|
97
|
+
# source_template_from_path("/path/to/site/src/stylesheets/application.sass") -> "application"
|
|
98
|
+
def source_template_from_path(path)
|
|
99
|
+
file_dir, file_name = File.split(path)
|
|
100
|
+
file_name.chomp!(File.extname(file_name))
|
|
101
|
+
[ file_dir, file_name, File.extname(path) ]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'rack/utils'
|
|
3
|
+
require 'sprockets/errors'
|
|
4
|
+
require 'sprockets/utils'
|
|
5
|
+
require 'pathname'
|
|
6
|
+
require 'set'
|
|
7
|
+
|
|
8
|
+
module ProcessIt
|
|
9
|
+
# `Context` provides helper methods to all `Tilt` processors. They
|
|
10
|
+
# are typically accessed by ERB templates. You can mix in custom
|
|
11
|
+
# helpers by injecting them into `Environment#context_class`. Do not
|
|
12
|
+
# mix them into `Context` directly.
|
|
13
|
+
#
|
|
14
|
+
# environment.context_class.class_eval do
|
|
15
|
+
# include MyHelper
|
|
16
|
+
# def asset_url; end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# <%= asset_url "foo.png" %>
|
|
20
|
+
#
|
|
21
|
+
# The `Context` also collects dependencies declared by
|
|
22
|
+
# assets. See `DirectiveProcessor` for an example of this.
|
|
23
|
+
class Context
|
|
24
|
+
attr_reader :environment, :pathname
|
|
25
|
+
attr_reader :_required_paths, :_stubbed_assets
|
|
26
|
+
attr_reader :_dependency_paths, :_dependency_assets
|
|
27
|
+
attr_writer :__LINE__
|
|
28
|
+
|
|
29
|
+
def initialize(environment, logical_path, pathname)
|
|
30
|
+
@environment = environment
|
|
31
|
+
@logical_path = logical_path
|
|
32
|
+
@pathname = pathname
|
|
33
|
+
@__LINE__ = nil
|
|
34
|
+
|
|
35
|
+
@_required_paths = []
|
|
36
|
+
@_stubbed_assets = Set.new
|
|
37
|
+
@_dependency_paths = Set.new
|
|
38
|
+
@_dependency_assets = Set.new([pathname.to_s])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Returns the environment path that contains the file.
|
|
42
|
+
#
|
|
43
|
+
# If `app/javascripts` and `app/stylesheets` are in your path, and
|
|
44
|
+
# current file is `app/javascripts/foo/bar.js`, `root_path` would
|
|
45
|
+
# return `app/javascripts`.
|
|
46
|
+
def root_path
|
|
47
|
+
environment.paths.detect { |path| pathname.to_s[path] }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Returns logical path without any file extensions.
|
|
51
|
+
#
|
|
52
|
+
# 'app/javascripts/application.js'
|
|
53
|
+
# # => 'application'
|
|
54
|
+
#
|
|
55
|
+
def logical_path
|
|
56
|
+
@logical_path.chomp(File.extname(@logical_path))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Returns content type of file
|
|
60
|
+
#
|
|
61
|
+
# 'application/javascript'
|
|
62
|
+
# 'text/css'
|
|
63
|
+
#
|
|
64
|
+
def content_type
|
|
65
|
+
environment.content_type_of(pathname)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Given a logical path, `resolve` will find and return the fully
|
|
69
|
+
# expanded path. Relative paths will also be resolved. An optional
|
|
70
|
+
# `:content_type` restriction can be supplied to restrict the
|
|
71
|
+
# search.
|
|
72
|
+
#
|
|
73
|
+
# resolve("foo.js")
|
|
74
|
+
# # => "/path/to/app/javascripts/foo.js"
|
|
75
|
+
#
|
|
76
|
+
# resolve("./bar.js")
|
|
77
|
+
# # => "/path/to/app/javascripts/bar.js"
|
|
78
|
+
#
|
|
79
|
+
def resolve(path, options = {}, &block)
|
|
80
|
+
pathname = Pathname.new(path)
|
|
81
|
+
attributes = environment.attributes_for(pathname)
|
|
82
|
+
|
|
83
|
+
if pathname.absolute?
|
|
84
|
+
pathname
|
|
85
|
+
|
|
86
|
+
elsif content_type = options[:content_type]
|
|
87
|
+
content_type = self.content_type if content_type == :self
|
|
88
|
+
|
|
89
|
+
if attributes.format_extension
|
|
90
|
+
if content_type != attributes.content_type
|
|
91
|
+
raise ContentTypeMismatch, "#{path} is " +
|
|
92
|
+
"'#{attributes.content_type}', not '#{content_type}'"
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
resolve(path) do |candidate|
|
|
97
|
+
if self.content_type == environment.content_type_of(candidate)
|
|
98
|
+
return candidate
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
raise FileNotFound, "couldn't find file '#{path}'"
|
|
103
|
+
else
|
|
104
|
+
environment.resolve(path, {:base_path => self.pathname.dirname}.merge(options), &block)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# `depend_on` allows you to state a dependency on a file without
|
|
109
|
+
# including it.
|
|
110
|
+
#
|
|
111
|
+
# This is used for caching purposes. Any changes made to
|
|
112
|
+
# the dependency file with invalidate the cache of the
|
|
113
|
+
# source file.
|
|
114
|
+
def depend_on(path)
|
|
115
|
+
@_dependency_paths << resolve(path).to_s
|
|
116
|
+
nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# `depend_on_asset` allows you to state an asset dependency
|
|
120
|
+
# without including it.
|
|
121
|
+
#
|
|
122
|
+
# This is used for caching purposes. Any changes that would
|
|
123
|
+
# invalidate the dependency asset will invalidate the source
|
|
124
|
+
# file. Unlike `depend_on`, this will include recursively include
|
|
125
|
+
# the target asset's dependencies.
|
|
126
|
+
def depend_on_asset(path)
|
|
127
|
+
filename = resolve(path).to_s
|
|
128
|
+
@_dependency_assets << filename
|
|
129
|
+
nil
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# `require_asset` declares `path` as a dependency of the file. The
|
|
133
|
+
# dependency will be inserted before the file and will only be
|
|
134
|
+
# included once.
|
|
135
|
+
#
|
|
136
|
+
# If ERB processing is enabled, you can use it to dynamically
|
|
137
|
+
# require assets.
|
|
138
|
+
#
|
|
139
|
+
# <%= require_asset "#{framework}.js" %>
|
|
140
|
+
#
|
|
141
|
+
def require_asset(path)
|
|
142
|
+
pathname = resolve(path, :content_type => :self)
|
|
143
|
+
depend_on_asset(pathname)
|
|
144
|
+
@_required_paths << pathname.to_s
|
|
145
|
+
nil
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# `stub_asset` blacklists `path` from being included in the bundle.
|
|
149
|
+
# `path` must be an asset which may or may not already be included
|
|
150
|
+
# in the bundle.
|
|
151
|
+
def stub_asset(path)
|
|
152
|
+
@_stubbed_assets << resolve(path, :content_type => :self).to_s
|
|
153
|
+
nil
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Tests if target path is able to be safely required into the
|
|
157
|
+
# current concatenation.
|
|
158
|
+
def asset_requirable?(path)
|
|
159
|
+
pathname = resolve(path)
|
|
160
|
+
content_type = environment.content_type_of(pathname)
|
|
161
|
+
stat = environment.stat(path)
|
|
162
|
+
return false unless stat && stat.file?
|
|
163
|
+
self.content_type.nil? || self.content_type == content_type
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Reads `path` and runs processors on the file.
|
|
167
|
+
#
|
|
168
|
+
# This allows you to capture the result of an asset and include it
|
|
169
|
+
# directly in another.
|
|
170
|
+
#
|
|
171
|
+
# <%= evaluate "bar.js" %>
|
|
172
|
+
#
|
|
173
|
+
def evaluate(path, options = {})
|
|
174
|
+
pathname = resolve(path)
|
|
175
|
+
attributes = environment.attributes_for(pathname)
|
|
176
|
+
processors = options[:processors] || attributes.processors
|
|
177
|
+
|
|
178
|
+
if options[:data]
|
|
179
|
+
result = options[:data]
|
|
180
|
+
else
|
|
181
|
+
if environment.respond_to?(:default_external_encoding)
|
|
182
|
+
mime_type = environment.mime_types(pathname.extname)
|
|
183
|
+
encoding = environment.encoding_for_mime_type(mime_type)
|
|
184
|
+
result = Sprockets::Utils.read_unicode(pathname, encoding)
|
|
185
|
+
else
|
|
186
|
+
result = Sprockets::Utils.read_unicode(pathname)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
processors.each do |processor|
|
|
191
|
+
|
|
192
|
+
begin
|
|
193
|
+
template = processor.new(pathname.to_s) { result }
|
|
194
|
+
result = template.render(self, {})
|
|
195
|
+
rescue Exception => e
|
|
196
|
+
annotate_exception! e
|
|
197
|
+
raise
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
result
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Returns a Base64-encoded `data:` URI with the contents of the
|
|
205
|
+
# asset at the specified path, and marks that path as a dependency
|
|
206
|
+
# of the current file.
|
|
207
|
+
#
|
|
208
|
+
# Use `asset_data_uri` from ERB with CSS or JavaScript assets:
|
|
209
|
+
#
|
|
210
|
+
# #logo { background: url(<%= asset_data_uri 'logo.png' %>) }
|
|
211
|
+
#
|
|
212
|
+
# $('<img>').attr('src', '<%= asset_data_uri 'avatar.jpg' %>')
|
|
213
|
+
#
|
|
214
|
+
def asset_data_uri(path)
|
|
215
|
+
depend_on_asset(path)
|
|
216
|
+
asset = environment.find_asset(path)
|
|
217
|
+
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
|
|
218
|
+
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
private
|
|
222
|
+
# Annotates exception backtrace with the original template that
|
|
223
|
+
# the exception was raised in.
|
|
224
|
+
def annotate_exception!(exception)
|
|
225
|
+
location = pathname.to_s
|
|
226
|
+
location << ":#{@__LINE__}" if @__LINE__
|
|
227
|
+
|
|
228
|
+
exception.extend(Sprockets::EngineError)
|
|
229
|
+
exception.sprockets_annotation = " (in #{location})"
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def logger
|
|
233
|
+
environment.logger
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|