ruby-clean-css 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-clean-css (0.0.2)
4
+ ruby-clean-css (0.0.3)
5
5
  commonjs
6
6
  therubyracer
7
7
 
@@ -13,6 +13,7 @@ GEM
13
13
  crack (0.4.2)
14
14
  safe_yaml (~> 1.0.0)
15
15
  libv8 (3.16.14.3)
16
+ rake (10.3.2)
16
17
  ref (1.0.5)
17
18
  safe_yaml (1.0.3)
18
19
  therubyracer (0.12.1)
@@ -26,5 +27,6 @@ PLATFORMS
26
27
  ruby
27
28
 
28
29
  DEPENDENCIES
30
+ rake
29
31
  ruby-clean-css!
30
32
  webmock
data/README.md CHANGED
@@ -11,10 +11,17 @@ compressor](https://github.com/sstephenson/ruby-yui-compressor) (which was
11
11
  by Yahoo in 2012).
12
12
 
13
13
 
14
+ ## Installation
15
+
16
+ It's a gem!
17
+
18
+ $ gem install ruby-clean-css
19
+
20
+
14
21
  ## Usage
15
22
 
16
23
  You can use this library with Rails, or with Sprockets in non-Rails projects,
17
- or simply as a standalone library.
24
+ or as a standalone library.
18
25
 
19
26
 
20
27
  ### As a plain Ruby library:
@@ -61,7 +68,7 @@ options](https://github.com/GoalSmashers/clean-css#how-to-use-clean-css-programm
61
68
  - `keep_special_comments` - A "special comment" is one that begins with `/*!`.
62
69
  You can keep them all with `:all`, just the first with `:first`, or
63
70
  remove them all with `:none`. The default is `:all`.
64
- - `keep_breaks` - By default, all linebreaks are stripped. Set to `true` to
71
+ - `keep_breaks` - By default, all linebreaks are stripped. Set to `true` to
65
72
  retain them.
66
73
  - `root` - This is the path used to resolve absolute `@import` rules and rebase
67
74
  relative URLS. A string. Defaults to the present working directory.
@@ -69,36 +76,62 @@ options](https://github.com/GoalSmashers/clean-css#how-to-use-clean-css-programm
69
76
  URLs. A string. No default.
70
77
  - `process_import` - By default, stylesheets included via `@import` are fetched
71
78
  and minified inline. Set to false to retain `@import` lines unmodified.
72
- - `rebase_urls` - By default, all URLs are rebased to the root. Set to `false`
79
+ - `rebase_urls` - By default, all URLs are rebased to the root. Set to `false`
73
80
  to prevent rebasing.
74
81
  - `advanced` - By default, Clean-CSS applies some advanced optimizations,
75
82
  like selector and property merging, reduction, etc). Set to `false` to
76
- prevent these optimizations.
83
+ prevent these optimizations.
77
84
  - `rounding_precision` - The rounding precision on measurements in your CSS.
78
85
  An integer, defaulting to `2`.
79
86
  - `compatibility` - Use this to force Clean-CSS to be compatible with `ie7`
80
- or `ie8`. Default is neither. Supply as a symbol (`:ie7`) or
87
+ or `ie8`. Default is neither. Supply as a symbol (`:ie7`) or
81
88
  string (`'ie7'`).
82
-
83
- The following options are not yet supported by this library:
84
-
85
- - `benchmark`
86
- - `debug`
89
+ - `benchmark` - If set to true, will output the duration of each regex
90
+ replacement in ms to STDERR.
91
+ - `debug` - If set to true, Clean-CSS will output explanatory information
92
+ to STDERR.
87
93
 
88
94
  In keeping with the Node library's interface, there are some synonyms available:
89
95
 
90
96
  - `:no_rebase => true` is the same as `:rebase_urls => false`.
91
97
  - `:no_advanced => true` is the same as `:advanced => false`.
92
- - `:keep_special_comments` has an alternative syntax: `'*'` means `:all`,
98
+ - `:keep_special_comments` has an alternative syntax: `'*'` means `:all`,
93
99
  `1` means `:first` and `0` means `:none`.
94
100
 
95
101
 
96
- ## Contributing
102
+ ## Rails local precompilation (reducing production dependencies)
97
103
 
98
- Pull requests are welcome. Please supply a test case with your PR. You
99
- typically run tests like this:
104
+ This is only relevant if a) you're using Rails and b) you always do local
105
+ asset precompilation.
106
+
107
+ V8 is a significant dependency to add to production servers just to
108
+ minimise some code. That doesn't seem to bother most people, but if (like me)
109
+ you zealously weed out unnecessary dependencies, you may prefer to do
110
+ your asset precompilation on your dev machine (or a build server or similar).
111
+ In this case, you don't want to add the gem to the `:assets` group in your
112
+ Gemfile. You want it in the `:development` group -- gems in this group are
113
+ not typically bundled onto production servers.
114
+
115
+ Having done that, there may be another step before Rails will use
116
+ Ruby-Clean-CSS for asset compression. Create `lib/tasks/assets.rake` and
117
+ add this code:
118
+
119
+ namespace(:assets) do
120
+ task(:environment) do
121
+ require('ruby-clean-css')
122
+ require('ruby-clean-css/sprockets')
123
+ RubyCleanCSS::Sprockets.register(Rails.application.assets)
124
+ Rails.application.config.assets.css_compressor = :cleancss
125
+ end
126
+ end
127
+
128
+ That's it. You don't need to change any practices. `rake assets:precompile`
129
+ will now work like you expect.
130
+
131
+
132
+ ## Contributing
100
133
 
101
- bundle exec ruby test/test_compressor.rb
134
+ Pull requests are welcome. Please supply a test case with your PR.
102
135
 
103
136
  ## License
104
137
 
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require('rake/testtask')
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs += ['lib']
5
+ t.test_files = FileList['test/test_*.rb']
6
+ t.verbose = true
7
+ end
8
+
9
+ task(:default => :test)
@@ -98,6 +98,10 @@ class RubyCleanCSS::Compressor
98
98
  js_opts['relativeTo'] = options[:relative_to].to_s
99
99
  end
100
100
 
101
+ if options.has_key?(:process_import)
102
+ js_opts['processImport'] = options[:process_import] ? true : false
103
+ end
104
+
101
105
  if options.has_key?(:no_rebase)
102
106
  js_opts['noRebase'] = options[:no_rebase] ? true : false
103
107
  elsif !options[:rebase_urls].nil?
@@ -124,16 +128,12 @@ class RubyCleanCSS::Compressor
124
128
  end
125
129
  end
126
130
 
127
- if options.has_key?(:process_import)
128
- raise('Ruby-Clean-CSS: processImport option is not yet supported')
129
- end
130
-
131
131
  if options.has_key?(:benchmark)
132
- raise('Ruby-Clean-CSS: benchmark option is not yet supported')
132
+ js_opts['benchmark'] = options[:benchmark] ? true : false
133
133
  end
134
134
 
135
135
  if options.has_key?(:debug)
136
- raise('Ruby-Clean-CSS: debug option is not yet supported')
136
+ js_opts['debug'] = options[:debug] ? true : false
137
137
  end
138
138
 
139
139
  js_opts
@@ -13,6 +13,11 @@ module RubyCleanCSS::Exports
13
13
 
14
14
  class Process # :nodoc:
15
15
 
16
+ def initialize
17
+ @init_time = Time.now
18
+ end
19
+
20
+
16
21
  def nextTick
17
22
  lambda { |global, fn| fn.call }
18
23
  end
@@ -23,6 +28,15 @@ module RubyCleanCSS::Exports
23
28
  end
24
29
 
25
30
 
31
+ def hrtime
32
+ lambda { |this, hrt|
33
+ hrt = hrt || [0,0]
34
+ delta = Time.now - @init_time
35
+ [delta.to_i - hrt[0], (delta % 1 * 1000000000).to_i - hrt[1]]
36
+ }
37
+ end
38
+
39
+
26
40
  def exit(*args)
27
41
  warn("JS process.exit(#{args.first}) called from: \n#{caller.join("\n")}")
28
42
  end
@@ -34,13 +48,13 @@ module RubyCleanCSS::Exports
34
48
  class Console # :nodoc:
35
49
 
36
50
  def log(*msgs)
37
- STDOUT.puts(msgs.join(', '))
51
+ str = sprintf(*msgs) rescue msgs.join(', ')
52
+ STDERR.puts(str)
38
53
  end
39
54
 
40
55
 
41
- def warn(*msgs)
42
- STDERR.puts(msgs.join(', '))
43
- end
56
+ alias :warn :log
57
+ alias :error :log
44
58
 
45
59
  end
46
60
 
@@ -1,5 +1,5 @@
1
1
  module RubyCleanCSS
2
2
 
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
 
5
5
  end
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.version = RubyCleanCSS::VERSION
16
16
  gem.add_dependency('therubyracer')
17
17
  gem.add_dependency('commonjs')
18
+ gem.add_development_dependency('rake')
18
19
  gem.add_development_dependency('webmock')
19
20
 
20
21
  # Append all submodule files to the list of gem files.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-clean-css
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2014-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: therubyracer
16
- requirement: &6025560 !ruby/object:Gem::Requirement
16
+ requirement: &6455220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *6025560
24
+ version_requirements: *6455220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commonjs
27
- requirement: &6024460 !ruby/object:Gem::Requirement
27
+ requirement: &6453300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *6024460
35
+ version_requirements: *6453300
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &6452640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *6452640
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: webmock
38
- requirement: &6023840 !ruby/object:Gem::Requirement
49
+ requirement: &6452000 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,7 +54,7 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *6023840
57
+ version_requirements: *6452000
47
58
  description: A Ruby interface to the Clean-CSS minifier for Node.
48
59
  email:
49
60
  - jpearson@overdrive.com
@@ -57,6 +68,7 @@ files:
57
68
  - Gemfile.lock
58
69
  - LICENSE
59
70
  - README.md
71
+ - Rakefile
60
72
  - lib/ruby-clean-css.rb
61
73
  - lib/ruby-clean-css/compressor.rb
62
74
  - lib/ruby-clean-css/exports.rb