assets-compiler 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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/assets-compiler.gemspec +23 -0
- data/lib/assets-compiler.rb +2 -0
- data/lib/assets/compiler.rb +24 -0
- data/lib/assets/compiler/base.rb +48 -0
- data/lib/assets/compiler/checker.rb +24 -0
- data/lib/assets/compiler/javascript.rb +14 -0
- data/lib/assets/compiler/plugin/rack.rb +35 -0
- data/lib/assets/compiler/plugin/rails.rb +25 -0
- data/lib/assets/compiler/version.rb +5 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "assets/compiler/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "assets-compiler"
|
7
|
+
s.version = Assets::Compiler::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = "Jonathan Tropper"
|
10
|
+
s.email = "tropperstyle@gmail.com"
|
11
|
+
s.homepage = "http://rubygems.org/gems/assets-compiler"
|
12
|
+
s.summary = "A static asset compiler"
|
13
|
+
s.description = "Can be used to compile any static assets (etc minify javascript)"
|
14
|
+
|
15
|
+
s.rubyforge_project = "assets-compiler"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('closure-compiler', '>= 1.0.0')
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Assets
|
2
|
+
module Compiler
|
3
|
+
extend self
|
4
|
+
|
5
|
+
attr_accessor :config, :compilers
|
6
|
+
|
7
|
+
DEFAULTS = {}
|
8
|
+
|
9
|
+
def init!(options)
|
10
|
+
self.config = options.reverse_merge(DEFAULTS)
|
11
|
+
self.compilers = []
|
12
|
+
|
13
|
+
config[:compilers].each do |key, paths|
|
14
|
+
compilers << Base.create(key, paths)
|
15
|
+
end
|
16
|
+
|
17
|
+
compile!
|
18
|
+
end
|
19
|
+
|
20
|
+
def compile!
|
21
|
+
compilers.each(&:compile!)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Assets
|
2
|
+
module Compiler
|
3
|
+
class InvalidCompiler < NameError; end
|
4
|
+
|
5
|
+
class Base
|
6
|
+
attr_accessor :source_path, :destination_path, :staleness_checker
|
7
|
+
|
8
|
+
def self.create(type, paths)
|
9
|
+
begin
|
10
|
+
klass = Assets::Compiler.const_get(type.to_s.capitalize)
|
11
|
+
rescue NameError
|
12
|
+
raise InvalidCompiler, "No compiler found for #{type}"
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.new(paths)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(paths)
|
19
|
+
self.source_path, self.destination_path = paths
|
20
|
+
self.staleness_checker = Checker.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def compile!
|
24
|
+
outdated_files.each do |file|
|
25
|
+
destination_file = destination_for_file(file)
|
26
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
27
|
+
compile_file(file, destination_file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destination_for_file(file)
|
32
|
+
relative_path = file.sub(source_path, '')
|
33
|
+
File.join(destination_path, relative_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def outdated_files
|
39
|
+
staleness_checker.outdated_files
|
40
|
+
end
|
41
|
+
|
42
|
+
def compile_file(file, destination_file)
|
43
|
+
File.copy(file, destination_file)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Assets
|
2
|
+
module Compiler
|
3
|
+
class Checker
|
4
|
+
attr_accessor :compiler
|
5
|
+
|
6
|
+
def initialize(_compiler)
|
7
|
+
self.compiler = _compiler
|
8
|
+
end
|
9
|
+
|
10
|
+
def outdated_files
|
11
|
+
files.select do |file|
|
12
|
+
compiled_file = compiler.destination_for_file(file)
|
13
|
+
!File.exists?(compiled_file) || File.mtime(file) > File.mtime(compiled_file)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def files
|
20
|
+
Dir.glob(File.join(compiler.source_path, '**', '*')).select { |f| File.file?(f) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Assets
|
2
|
+
module Compiler
|
3
|
+
class Javascript < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def compile_file(file, destination_file)
|
8
|
+
source = Closure::Compiler.new.compile(File.open(file, 'r'))
|
9
|
+
File.open(destination_file, 'w') { |f| f.write(source) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Taken from nex3 sass
|
2
|
+
module Assets
|
3
|
+
module Compiler
|
4
|
+
module Plugin
|
5
|
+
class Rack
|
6
|
+
# The delay, in seconds, between update checks.
|
7
|
+
# Useful when many resources are requested for a single page.
|
8
|
+
# `nil` means no delay at all.
|
9
|
+
#
|
10
|
+
# @return [Float]
|
11
|
+
attr_accessor :dwell
|
12
|
+
|
13
|
+
# Initialize the middleware.
|
14
|
+
#
|
15
|
+
# @param app [#call] The Rack application
|
16
|
+
# @param dwell [Float] See \{#dwell}
|
17
|
+
def initialize(app, dwell = 1.0)
|
18
|
+
@app = app
|
19
|
+
@dwell = dwell
|
20
|
+
@check_after = Time.now.to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param env The Rack request environment
|
24
|
+
# @return [(#to_i, {String => String}, Object)] The Rack response
|
25
|
+
def call(env)
|
26
|
+
if @dwell.nil? || Time.now.to_f > @check_after
|
27
|
+
Assets::Compiler.compile!
|
28
|
+
@check_after = Time.now.to_f + @dwell if @dwell
|
29
|
+
end
|
30
|
+
@app.call(env)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Taken from nex3 sass
|
2
|
+
if defined?(Rails)
|
3
|
+
# Rails >= 3.0
|
4
|
+
if defined?(ActionController::Metal)
|
5
|
+
require 'assets/compiler/plugin/rack'
|
6
|
+
Rails.configuration.middleware.use(Assets::Compiler::Plugin::Rack)
|
7
|
+
|
8
|
+
# Rails >= 2.3
|
9
|
+
elsif defined?(ActionController::Dispatcher) && defined?(ActionController::Dispatcher.middleware)
|
10
|
+
require 'assets/compiler/plugin/rack'
|
11
|
+
ActionController::Dispatcher.middleware.use(Assets::Compiler::Plugin::Rack)
|
12
|
+
|
13
|
+
else
|
14
|
+
module ActionController
|
15
|
+
class Base
|
16
|
+
alias_method :sass_old_process, :process
|
17
|
+
def process(*args)
|
18
|
+
Sass::Plugin.check_for_updates
|
19
|
+
Assets::Compiler.compile!
|
20
|
+
sass_old_process(*args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: assets-compiler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jonathan Tropper
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-11 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: closure-compiler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 23
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Can be used to compile any static assets (etc minify javascript)
|
37
|
+
email: tropperstyle@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- assets-compiler.gemspec
|
49
|
+
- lib/assets-compiler.rb
|
50
|
+
- lib/assets/compiler.rb
|
51
|
+
- lib/assets/compiler/base.rb
|
52
|
+
- lib/assets/compiler/checker.rb
|
53
|
+
- lib/assets/compiler/javascript.rb
|
54
|
+
- lib/assets/compiler/plugin/rack.rb
|
55
|
+
- lib/assets/compiler/plugin/rails.rb
|
56
|
+
- lib/assets/compiler/version.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://rubygems.org/gems/assets-compiler
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: assets-compiler
|
87
|
+
rubygems_version: 1.4.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: A static asset compiler
|
91
|
+
test_files: []
|
92
|
+
|