assette 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -8,6 +8,10 @@ group :development do
8
8
  gem "rcov", ">= 0"
9
9
  end
10
10
 
11
- gem "json"
12
- gem "haml"
13
- gem "mime-types", ">= 1.16", :require => 'mime/types'
11
+ gem "rack", '~> 1'
12
+ gem "thor", '~> 0'
13
+ gem "json", '>= 1.4'
14
+ gem "haml", '~> 3'
15
+ gem "mime-types", ">= 1.16", :require => 'mime/types'
16
+ gem "git"
17
+ gem "coffee-script", "~> 2"
data/Gemfile.lock CHANGED
@@ -1,7 +1,12 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ coffee-script (2.2.0)
5
+ coffee-script-source
6
+ execjs
7
+ coffee-script-source (1.0.1)
4
8
  diff-lcs (1.1.2)
9
+ execjs (0.1.0)
5
10
  git (1.2.5)
6
11
  haml (3.0.25)
7
12
  jeweler (1.5.2)
@@ -10,6 +15,7 @@ GEM
10
15
  rake
11
16
  json (1.5.1)
12
17
  mime-types (1.16)
18
+ rack (1.2.1)
13
19
  rake (0.8.7)
14
20
  rcov (0.9.9)
15
21
  rspec (2.4.0)
@@ -20,6 +26,7 @@ GEM
20
26
  rspec-expectations (2.4.0)
21
27
  diff-lcs (~> 1.1.2)
22
28
  rspec-mocks (2.4.0)
29
+ thor (0.14.6)
23
30
  yard (0.6.4)
24
31
 
25
32
  PLATFORMS
@@ -27,10 +34,14 @@ PLATFORMS
27
34
 
28
35
  DEPENDENCIES
29
36
  bundler (~> 1.0.0)
30
- haml
37
+ coffee-script (~> 2)
38
+ git
39
+ haml (~> 3)
31
40
  jeweler (~> 1.5.2)
32
- json
41
+ json (>= 1.4)
33
42
  mime-types (>= 1.16)
43
+ rack (~> 1)
34
44
  rcov
35
45
  rspec (~> 2.4.0)
46
+ thor (~> 0)
36
47
  yard (~> 0.6.0)
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = assette
2
2
 
3
- Description goes here.
3
+ I really need to add documentation
4
4
 
5
5
  == Contributing to assette
6
6
 
data/Rakefile CHANGED
@@ -15,14 +15,19 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "assette"
16
16
  gem.homepage = "http://github.com/Talby/assette"
17
17
  gem.license = "MIT"
18
- gem.summary = %Q{Asset manager thing}
19
- gem.description = %Q{longer description of your gem}
18
+ gem.summary = %Q{Treat all assets as equal}
19
+ gem.description = %Q{Renders all asset types (coffeescript/sass/scss) as equals}
20
20
  gem.email = "me@tal.by"
21
21
  gem.authors = ["Tal Atlas"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
23
23
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- gem.add_runtime_dependency 'mime-types', '>= 1.16'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
24
+ gem.add_runtime_dependency "rack", '~> 1'
25
+ gem.add_runtime_dependency "thor", '~> 0'
26
+ gem.add_runtime_dependency "json", '>= 1.4'
27
+ gem.add_runtime_dependency "haml", '~> 3'
28
+ gem.add_runtime_dependency "coffee-script", '~> 2'
29
+ # gem.add_runtime_dependency "git"
30
+ gem.add_runtime_dependency "mime-types", ">= 1.16"
26
31
  end
27
32
  Jeweler::RubygemsDotOrgTasks.new
28
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/assette.gemspec CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{assette}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tal Atlas"]
12
- s.date = %q{2011-03-06}
13
- s.description = %q{longer description of your gem}
12
+ s.date = %q{2011-03-28}
13
+ s.default_executable = %q{assette}
14
+ s.description = %q{Renders all asset types (coffeescript/sass/scss) as equals}
14
15
  s.email = %q{me@tal.by}
16
+ s.executables = ["assette"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE.txt",
17
19
  "README.rdoc"
@@ -26,12 +28,13 @@ Gem::Specification.new do |s|
26
28
  "Rakefile",
27
29
  "VERSION",
28
30
  "assette.gemspec",
29
- "examples/app/templates/foo/index.html.mustache",
30
- "examples/config.ru",
31
- "examples/defaults.rb",
32
- "examples/defaults.yml",
31
+ "bin/assette",
32
+ "examples/config/assets.rb",
33
+ "examples/myapp/templates/foo/_partial.html.mustache",
34
+ "examples/myapp/templates/foo/index.html.mustache",
33
35
  "examples/public/images/test.pdf",
34
36
  "examples/public/javascripts/foo.js",
37
+ "examples/public/javascripts/handlebars.js",
35
38
  "examples/public/javascripts/one.js",
36
39
  "examples/public/javascripts/test.coffee",
37
40
  "examples/public/javascripts/three.js",
@@ -41,9 +44,13 @@ Gem::Specification.new do |s|
41
44
  "examples/public/stylesheets/two.css",
42
45
  "examples/public/stylesheets/two2.scss",
43
46
  "lib/assette.rb",
47
+ "lib/assette/cli.rb",
44
48
  "lib/assette/compiled_file.rb",
45
49
  "lib/assette/config.rb",
46
50
  "lib/assette/file.rb",
51
+ "lib/assette/post_processor.rb",
52
+ "lib/assette/post_processors.rb",
53
+ "lib/assette/post_processors/cache_buster.rb",
47
54
  "lib/assette/reader.rb",
48
55
  "lib/assette/readers.rb",
49
56
  "lib/assette/readers/coffee.rb",
@@ -51,25 +58,32 @@ Gem::Specification.new do |s|
51
58
  "lib/assette/readers/js.rb",
52
59
  "lib/assette/readers/sass.rb",
53
60
  "lib/assette/readers/scss.rb",
61
+ "lib/assette/run.ru",
54
62
  "lib/assette/server.rb",
55
63
  "lib/assette/template.rb",
56
64
  "lib/assette/template_set.rb",
57
65
  "spec/assette_spec.rb",
66
+ "spec/config_spec.rb",
58
67
  "spec/file_spec.rb",
68
+ "spec/post_processor_spec.rb",
59
69
  "spec/reader_spec.rb",
70
+ "spec/server_spec.rb",
60
71
  "spec/spec_helper.rb",
61
72
  "spec/template_spec.rb"
62
73
  ]
63
74
  s.homepage = %q{http://github.com/Talby/assette}
64
75
  s.licenses = ["MIT"]
65
76
  s.require_paths = ["lib"]
66
- s.rubygems_version = %q{1.5.0}
67
- s.summary = %q{Asset manager thing}
77
+ s.rubygems_version = %q{1.5.2}
78
+ s.summary = %q{Treat all assets as equal}
68
79
  s.test_files = [
69
- "examples/defaults.rb",
80
+ "examples/config/assets.rb",
70
81
  "spec/assette_spec.rb",
82
+ "spec/config_spec.rb",
71
83
  "spec/file_spec.rb",
84
+ "spec/post_processor_spec.rb",
72
85
  "spec/reader_spec.rb",
86
+ "spec/server_spec.rb",
73
87
  "spec/spec_helper.rb",
74
88
  "spec/template_spec.rb"
75
89
  ]
@@ -78,35 +92,62 @@ Gem::Specification.new do |s|
78
92
  s.specification_version = 3
79
93
 
80
94
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
81
- s.add_runtime_dependency(%q<json>, [">= 0"])
82
- s.add_runtime_dependency(%q<haml>, [">= 0"])
95
+ s.add_runtime_dependency(%q<rack>, ["~> 1"])
96
+ s.add_runtime_dependency(%q<thor>, ["~> 0"])
97
+ s.add_runtime_dependency(%q<json>, [">= 1.4"])
98
+ s.add_runtime_dependency(%q<haml>, ["~> 3"])
83
99
  s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
100
+ s.add_runtime_dependency(%q<git>, [">= 0"])
101
+ s.add_runtime_dependency(%q<coffee-script>, ["~> 2"])
84
102
  s.add_development_dependency(%q<rspec>, ["~> 2.4.0"])
85
103
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
86
104
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
87
105
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
88
106
  s.add_development_dependency(%q<rcov>, [">= 0"])
107
+ s.add_runtime_dependency(%q<rack>, ["~> 1"])
108
+ s.add_runtime_dependency(%q<thor>, ["~> 0"])
109
+ s.add_runtime_dependency(%q<json>, [">= 1.4"])
110
+ s.add_runtime_dependency(%q<haml>, ["~> 3"])
111
+ s.add_runtime_dependency(%q<coffee-script>, ["~> 2"])
89
112
  s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
90
113
  else
91
- s.add_dependency(%q<json>, [">= 0"])
92
- s.add_dependency(%q<haml>, [">= 0"])
114
+ s.add_dependency(%q<rack>, ["~> 1"])
115
+ s.add_dependency(%q<thor>, ["~> 0"])
116
+ s.add_dependency(%q<json>, [">= 1.4"])
117
+ s.add_dependency(%q<haml>, ["~> 3"])
93
118
  s.add_dependency(%q<mime-types>, [">= 1.16"])
119
+ s.add_dependency(%q<git>, [">= 0"])
120
+ s.add_dependency(%q<coffee-script>, ["~> 2"])
94
121
  s.add_dependency(%q<rspec>, ["~> 2.4.0"])
95
122
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
96
123
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
97
124
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
98
125
  s.add_dependency(%q<rcov>, [">= 0"])
126
+ s.add_dependency(%q<rack>, ["~> 1"])
127
+ s.add_dependency(%q<thor>, ["~> 0"])
128
+ s.add_dependency(%q<json>, [">= 1.4"])
129
+ s.add_dependency(%q<haml>, ["~> 3"])
130
+ s.add_dependency(%q<coffee-script>, ["~> 2"])
99
131
  s.add_dependency(%q<mime-types>, [">= 1.16"])
100
132
  end
101
133
  else
102
- s.add_dependency(%q<json>, [">= 0"])
103
- s.add_dependency(%q<haml>, [">= 0"])
134
+ s.add_dependency(%q<rack>, ["~> 1"])
135
+ s.add_dependency(%q<thor>, ["~> 0"])
136
+ s.add_dependency(%q<json>, [">= 1.4"])
137
+ s.add_dependency(%q<haml>, ["~> 3"])
104
138
  s.add_dependency(%q<mime-types>, [">= 1.16"])
139
+ s.add_dependency(%q<git>, [">= 0"])
140
+ s.add_dependency(%q<coffee-script>, ["~> 2"])
105
141
  s.add_dependency(%q<rspec>, ["~> 2.4.0"])
106
142
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
107
143
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
108
144
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
109
145
  s.add_dependency(%q<rcov>, [">= 0"])
146
+ s.add_dependency(%q<rack>, ["~> 1"])
147
+ s.add_dependency(%q<thor>, ["~> 0"])
148
+ s.add_dependency(%q<json>, [">= 1.4"])
149
+ s.add_dependency(%q<haml>, ["~> 3"])
150
+ s.add_dependency(%q<coffee-script>, ["~> 2"])
110
151
  s.add_dependency(%q<mime-types>, [">= 1.16"])
111
152
  end
112
153
  end
data/bin/assette ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+ require 'assette'
5
+ require 'assette/cli'
6
+ require 'assette/server'
7
+
8
+
9
+ Assette::CLI.start
@@ -0,0 +1,19 @@
1
+ file_path 'public'
2
+ file_path 'foo'
3
+
4
+ asset_host 'http://cdn.gilt.com'
5
+ asset_hosts 'http://cdn1.gilt.com', 'http://cdn2.gilt.com'
6
+
7
+ asset_dir 'myassets'
8
+ templates_path 'myapp/templates'
9
+
10
+ template_preloader 'javascripts/handlebars.js'
11
+ template_partial 'Handlebars.registerPartial({*path*},{*template*});'
12
+
13
+ template_format 'GC.foo.t[{*path*}] = Handlebars.compile({*template*});'
14
+
15
+
16
+ after_compile do
17
+ a = 1
18
+ a + 2
19
+ end
@@ -0,0 +1,3 @@
1
+ <div>
2
+ Yo
3
+ </div>
@@ -3,4 +3,4 @@
3
3
  // @require two.js
4
4
  // /ASSETTE CONFIG
5
5
 
6
- window.foo = 'foo';
6
+ window.foo = 'foo' || "bar";
@@ -0,0 +1,3 @@
1
+ window.Handlebars = {}
2
+ Handlebars.registerPartial = function() {};
3
+ Handlebars.compile = function() {};
@@ -1,5 +1,6 @@
1
1
  # ASSETTE CONFIG
2
2
  # @require one.js
3
+ # @template foo
3
4
  # /ASSETTE CONFIG
4
5
 
5
6
  test = 'test'
@@ -1,2 +1,5 @@
1
1
  #one
2
- width: 400px + 400px
2
+ width: 400px + 400px
3
+
4
+ #foo
5
+ background: url(/images/mystuff/goat.se?test=1)
@@ -2,4 +2,12 @@
2
2
 
3
3
  #two {
4
4
  width: 800px*3
5
+ }
6
+
7
+ #foo2 {
8
+ background: url(/images/mystuff/goa-t.se)
9
+ }
10
+
11
+ #foo3 {
12
+ background: url(/images/mystuff/go_at.se)
5
13
  }
@@ -0,0 +1,172 @@
1
+ require 'thor'
2
+ require 'rack'
3
+ require 'rack/showexceptions'
4
+ require 'assette/server'
5
+ require 'fileutils'
6
+
7
+ begin
8
+ require 'git'
9
+ rescue LoadError
10
+ end
11
+
12
+ # Remove the chdir, not sure why he put that there.
13
+ # Bad hack, gotta figure out another way to fix this
14
+ class Rack::Server
15
+ def daemonize_app
16
+ if RUBY_VERSION < "1.9"
17
+ exit if fork
18
+ Process.setsid
19
+ exit if fork
20
+ # Dir.chdir "/"
21
+ STDIN.reopen "/dev/null"
22
+ STDOUT.reopen "/dev/null", "a"
23
+ STDERR.reopen "/dev/null", "a"
24
+ else
25
+ Process.daemon
26
+ end
27
+ end
28
+ end
29
+
30
+ module Assette
31
+
32
+ class CLI < Thor
33
+ ASSET_PREFIX_MATCHER = /^([a-f0-9]{9}|\d{6}_\d{6})\//
34
+
35
+
36
+ include Thor::Actions
37
+ DEFAULT_PID_FILE = '.assette_pid'
38
+ class_option :'config-file', :desc => 'config file to use', :type => :string
39
+
40
+ map "-v" => :version
41
+
42
+ desc 'version', 'displays current gem version'
43
+ def version
44
+ say Assette::VERSION
45
+ end
46
+
47
+ desc 'server', 'Launches the assette server (should only be used for dev or behind a cdn)'
48
+ method_option :port, :aliases => '-p', :type => :numeric
49
+ method_option :'dont-daemonize', :aliases => '-D', :type => :boolean
50
+ method_option :pid, :type => :string, :default => DEFAULT_PID_FILE, :description => 'file to store pid in'
51
+ def server(cmd = nil)
52
+ if cmd.nil? || cmd == 'start'
53
+
54
+ opts = {}
55
+ opts[:Port] = options[:port] || 4747
56
+ opts[:config] = File.join(File.dirname(__FILE__),'run.ru')
57
+
58
+ unless options['dont-daemonize']
59
+
60
+ if File.exist?(pid_file)
61
+ pid = File.open(pid_file).read.chomp.to_i
62
+ say "Server already running with PID #{pid}, killing before restart"
63
+ Process.kill("INT",pid)
64
+ end
65
+
66
+ opts[:daemonize] = true
67
+ opts[:pid] = pid_file
68
+ end
69
+
70
+ say "Starting Assette server on port #{opts[:Port]}"
71
+ ret = Rack::Server.start(opts)
72
+ elsif cmd == 'stop'
73
+ if File.exist?(pid_file)
74
+ pid = File.open(pid_file).read.chomp.to_i
75
+ say "Killing server with PID #{pid}"
76
+ Process.kill("INT",pid)
77
+ else
78
+ say "No pid file found at #{pid_file}"
79
+ end
80
+ end
81
+ end
82
+
83
+ desc "compile", "Compile all the assettes in a folder for static serving"
84
+ def compile
85
+ files = []
86
+ all_files = []
87
+ Assette.config.compiling = true
88
+
89
+ unless File.exist?('assets')
90
+ Dir.mkdir('assets')
91
+ end
92
+
93
+ sha = Git.open('.').log.first.sha[0...8] rescue Time.now.strftime("%y%m%d_%H%M%S")
94
+ Assette.config.sha = sha
95
+
96
+ Assette.config.file_paths.each do |path|
97
+ all_files |= Dir[File.join(path,'**',"*")]
98
+ Assette::Reader::ALL.keys.each do |extension|
99
+ files |= Dir[File.join(path,'**',"*.#{extension}")]
100
+ end
101
+ end
102
+
103
+ not_compiled = all_files - files
104
+
105
+ files.delete_if {|f| f =~ /\/_/} # remove any mixins to speed up process
106
+
107
+ files = files.collect {|f| Assette::File.open(f)}
108
+
109
+ File.open("assets/version","w") {|f| f.write(sha)}
110
+
111
+ container = if Assette.config.cache_method.to_s == 'path'
112
+ File.join(Assette.config.build_target,sha)
113
+ else
114
+ Assette.config.build_target
115
+ end
116
+
117
+ made_dirs = []
118
+
119
+ say "Compiling all asset files to #{container}"
120
+
121
+ files.each do |file|
122
+ target_path = file.target_path
123
+
124
+ Assette.config.file_paths.each do |p|
125
+ target_path.gsub!(p,'')
126
+ end
127
+
128
+ new_path = File.join(container,target_path)
129
+
130
+ create_file(new_path, file.all_code)
131
+ end
132
+
133
+ say "\nCopying all non-compiled assets to #{container}"
134
+ not_compiled.each do |file|
135
+ target_path = file.dup
136
+ Assette.config.file_paths.each do |p|
137
+ target_path.gsub!(p,'')
138
+ end
139
+
140
+ new_path = File.join(container,target_path)
141
+
142
+ copy_file(new_path, file)
143
+ end
144
+ end
145
+
146
+ def initialize(*)
147
+ super
148
+ get_services
149
+ end
150
+
151
+ private
152
+ def set_color *args
153
+ @shell.set_color(*args)
154
+ end
155
+
156
+ def get_services
157
+ Assette.config(options['config-file'])
158
+ end
159
+
160
+ def pid_file
161
+ @pid ||= begin
162
+ pid = options.pid
163
+ unless pid =~ /^\//
164
+ pid = File.expand_path(File.join(Dir.pwd,pid))
165
+ end
166
+
167
+ pid
168
+ end
169
+ end
170
+ end
171
+
172
+ end
@@ -1,5 +1,6 @@
1
1
  module Assette
2
2
  class CompiledFile < Array
3
+
3
4
  attr_reader :file
4
5
 
5
6
  def initialize(file)
@@ -10,10 +11,24 @@ module Assette
10
11
  c = []
11
12
  c << "\n"
12
13
  c << file.comment_str % "Start: #{d.path}"
13
- c << d.code
14
+ c << code_for_dependency(d)
14
15
  c << file.comment_str % "End: #{d.path}"
16
+
15
17
  self << c.join("\n")
16
18
  end
19
+
20
+ def post_process str
21
+ PostProcessor::POST_PROCESSORS[target_class.outputs].each do |processor|
22
+ p = processor.new(str)
23
+ str.replace(p.process)
24
+ end
25
+
26
+ str
27
+ end
28
+
29
+ def code_for_dependency d
30
+ post_process(d.code)
31
+ end
17
32
 
18
33
  def content_type
19
34
  return mime_type.content_type if mime_type
@@ -29,7 +44,11 @@ module Assette
29
44
  end
30
45
 
31
46
  def mime_type
32
- file.target_class.mime_type
47
+ target_class.mime_type
48
+ end
49
+
50
+ def target_class
51
+ file.target_class
33
52
  end
34
53
 
35
54
  end