less-js 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+ gem 'less-js-source'
5
+ gem 'execjs'
6
+ # Specify your gem's dependencies in ruby-less-js.gemspec
7
+ gemspec
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ Ruby LessJs
2
+ =================
3
+
4
+ Ruby LessJs is a bridge to the official Javascript-based Less.js compiler.
5
+
6
+ LessJs.compile File.read("css.less")
7
+
8
+
9
+ Installation
10
+ ------------
11
+
12
+ gem install less-js
13
+
14
+
15
+ Dependencies
16
+ ------------
17
+
18
+ This library depends on the `less-js-source` gem which will be
19
+ updated any time a new version of Less.js is released. (The
20
+ `less-js-source` gem's version number is synced with each
21
+ official Less.js release.) This way you can build against
22
+ different versions of Less.js by requiring the correct version of
23
+ the `less-js-source` gem.
24
+
25
+ *Note: verion 1.1.1 is tagged as 1.1.1.1 on the `less-js-source` gem.*
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
+ ### ExecJS
35
+
36
+ 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.
37
+
38
+ Lifted From
39
+ -----------
40
+
41
+ The template for this gem was lifted from [Joshua Peek's](https://github.com/josh) [ruby-coffee-script](https://github.com/josh/ruby-coffee-script) gem.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task :default => :test
7
+
8
+ Rake::TestTask.new do |t|
9
+ t.warning = true
10
+ end
11
+
data/lib/less-js.rb ADDED
@@ -0,0 +1 @@
1
+ require 'less_js'
data/lib/less_js.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'execjs'
2
+ require 'less_js/source'
3
+
4
+ module LessJs
5
+ EngineError = ExecJS::RuntimeError
6
+ CompilationError = ExecJS::ProgramError
7
+
8
+ module Source
9
+ def self.path
10
+ @path ||= ENV['LESSJS_SOURCE_PATH'] || bundled_path
11
+ end
12
+
13
+ def self.path=(path)
14
+ @contents = @version = @bare_option = @context = nil
15
+ @path = path
16
+ end
17
+
18
+ def self.contents
19
+ @contents ||= File.read(path)
20
+ end
21
+
22
+ def self.version
23
+ @version ||= contents[/Less.js Compiler v([\d.]+)/, 1]
24
+ end
25
+
26
+ def self.context
27
+ @context ||= ExecJS.compile(contents)
28
+ end
29
+ end
30
+
31
+ class << self
32
+ def engine
33
+ end
34
+
35
+ def engine=(engine)
36
+ end
37
+
38
+ def version
39
+ Source.version
40
+ end
41
+
42
+ def callback(error, tree)
43
+ puts tree.inspect
44
+ end
45
+
46
+ # Compile a script (String or IO) to CSS.
47
+ def compile(script, options = {})
48
+ script = script.read if script.respond_to?(:read)
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
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "less-js"
6
+ s.version = '0.1.0'
7
+
8
+ s.authors = ["Adnan Ali"]
9
+ s.email = ["adnan.ali@gmail.com"]
10
+ s.homepage = "https://github.com/thisduck/ruby-less-js"
11
+ s.summary = "Ruby Less.js Compiler"
12
+ s.description = <<-EOS
13
+ Ruby Less.js is a bridge to the JS Less.js compiler.
14
+ EOS
15
+
16
+
17
+ s.rubyforge_project = "less-js"
18
+
19
+ s.add_dependency 'less-js-source'
20
+ s.add_dependency 'execjs'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,29 @@
1
+ require 'less_js'
2
+ require 'test/unit'
3
+ require 'stringio'
4
+
5
+ class TestLessJs < Test::Unit::TestCase
6
+ def test_compile
7
+ assert_equal ".a {\n border: 4px;\n}\n",
8
+ LessJs.compile(".a { border: 2px * 2;}\n")
9
+ end
10
+
11
+ def test_compile_with_io
12
+ io = StringIO.new(".a { border: 2px * 2;}\n")
13
+ assert_equal ".a {\n border: 4px;\n}\n",
14
+ LessJs.compile(io)
15
+ end
16
+
17
+ def test_compilation_error
18
+ assert_raise LessJs::CompilationError do
19
+ LessJs.compile("&&&&.a")
20
+ end
21
+ end
22
+
23
+ def assert_exception_does_not_match(pattern)
24
+ yield
25
+ flunk "no exception raised"
26
+ rescue Exception => e
27
+ assert_no_match pattern, e.message
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: less-js
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Adnan Ali
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-21 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: less-js-source
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: execjs
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: "\t\tRuby Less.js is a bridge to the JS Less.js compiler.\n"
50
+ email:
51
+ - adnan.ali@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - README.md
62
+ - Rakefile
63
+ - lib/less-js.rb
64
+ - lib/less_js.rb
65
+ - ruby-less-js.gemspec
66
+ - test/test_less_js.rb
67
+ has_rdoc: true
68
+ homepage: https://github.com/thisduck/ruby-less-js
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project: less-js
97
+ rubygems_version: 1.6.1
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Ruby Less.js Compiler
101
+ test_files:
102
+ - test/test_less_js.rb