less-js 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'rake'
4
- gem 'less-js-source'
5
- gem 'execjs'
6
4
  # Specify your gem's dependencies in ruby-less-js.gemspec
7
5
  gemspec
data/README.md CHANGED
@@ -24,13 +24,6 @@ the `less-js-source` gem.
24
24
 
25
25
  *Note: verion 1.1.1 is tagged as 1.1.1.1 on the `less-js-source` gem.*
26
26
 
27
- ### JSON
28
-
29
- The `json` library is also required but is not explicitly stated as a
30
- gem dependency. If you're on Ruby 1.8 you'll need to install the
31
- `json` or `json_pure` gem. On Ruby 1.9, `json` is included in the
32
- standard library.
33
-
34
27
  ### ExecJS
35
28
 
36
29
  The [ExecJS](https://github.com/sstephenson/execjs) library is used to automatically choose the best JavaScript engine for your platform. Check out its [README](https://github.com/sstephenson/execjs/blob/master/README.md) for a complete list of supported engines.
@@ -2,8 +2,7 @@ require 'execjs'
2
2
  require 'less_js/source'
3
3
 
4
4
  module LessJs
5
- EngineError = ExecJS::RuntimeError
6
- CompilationError = ExecJS::ProgramError
5
+ class ParseError < StandardError; end
7
6
 
8
7
  module Source
9
8
  def self.path
@@ -11,7 +10,7 @@ module LessJs
11
10
  end
12
11
 
13
12
  def self.path=(path)
14
- @contents = @version = @bare_option = @context = nil
13
+ @contents = @version = @context = nil
15
14
  @path = path
16
15
  end
17
16
 
@@ -20,46 +19,39 @@ module LessJs
20
19
  end
21
20
 
22
21
  def self.version
23
- @version ||= contents[/Less.js Compiler v([\d.]+)/, 1]
22
+ @version ||= contents[/LESS - Leaner CSS v([\d.]+)/, 1]
24
23
  end
25
24
 
26
25
  def self.context
27
- @context ||= ExecJS.compile(contents)
26
+ @context ||= ExecJS.compile <<-EOS
27
+ #{contents}
28
+
29
+ function compile(data) {
30
+ var result;
31
+ new less.Parser().parse(data, function(error, tree) {
32
+ result = [error, tree.toCSS()];
33
+ });
34
+ return result;
35
+ }
36
+ EOS
28
37
  end
29
38
  end
30
39
 
31
40
  class << self
32
- def engine
33
- end
34
-
35
- def engine=(engine)
36
- end
37
-
38
41
  def version
39
42
  Source.version
40
43
  end
41
44
 
42
- def callback(error, tree)
43
- puts tree.inspect
44
- end
45
-
46
45
  # Compile a script (String or IO) to CSS.
47
46
  def compile(script, options = {})
48
47
  script = script.read if script.respond_to?(:read)
48
+ error, data = Source.context.call('compile', script)
49
49
 
50
- code = <<-EOS
51
- (function(input) {
52
- var resp = "error";
53
- new(less.Parser)().parse(input, function(error, tree) {
54
- resp = [error, tree.toCSS()]
55
- });
56
- return resp;
57
- })
58
- EOS
59
-
60
- (error, response) = Source.context.call(code, script)
61
- raise CompilationError, error if error
62
- response
50
+ if error
51
+ raise ParseError, error['message']
52
+ else
53
+ data
54
+ end
63
55
  end
64
56
  end
65
57
  end
@@ -3,10 +3,10 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "less-js"
6
- s.version = '0.1.0'
6
+ s.version = '0.1.1'
7
7
 
8
- s.authors = ["Adnan Ali"]
9
- s.email = ["adnan.ali@gmail.com"]
8
+ s.authors = ["Joshua Peek", "Adnan Ali"]
9
+ s.email = ["josh@joshpeek.com", "adnan.ali@gmail.com"]
10
10
  s.homepage = "https://github.com/thisduck/ruby-less-js"
11
11
  s.summary = "Ruby Less.js Compiler"
12
12
  s.description = <<-EOS
@@ -15,7 +15,7 @@ class TestLessJs < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_compilation_error
18
- assert_raise LessJs::CompilationError do
18
+ assert_raise LessJs::ParseError do
19
19
  LessJs.compile("&&&&.a")
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: less-js
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
+ - Joshua Peek
13
14
  - Adnan Ali
14
15
  autorequire:
15
16
  bindir: bin
@@ -48,6 +49,7 @@ dependencies:
48
49
  version_requirements: *id002
49
50
  description: "\t\tRuby Less.js is a bridge to the JS Less.js compiler.\n"
50
51
  email:
52
+ - josh@joshpeek.com
51
53
  - adnan.ali@gmail.com
52
54
  executables: []
53
55