m4assets 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +92 -0
- data/Rakefile +8 -0
- data/lib/m4assets/error.rb +5 -0
- data/lib/m4assets/processor.rb +19 -0
- data/lib/m4assets/version.rb +3 -0
- data/lib/m4assets.rb +20 -0
- data/m4assets.gemspec +21 -0
- data/test/helper.rb +2 -0
- data/test/test_config.rb +20 -0
- data/test/test_processor.rb +39 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tobias Svensson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
= M4Assets
|
2
|
+
|
3
|
+
Sprockets support for the {M4}[http://www.gnu.org/software/m4/] preprocessor.
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
M4Assets adds support for the GNU {M4}[http://www.gnu.org/software/m4/] general
|
8
|
+
purpose macro processor to sprockets, allowing you to use textual macros in eg.
|
9
|
+
your JavaScript, CoffeeScript, CSS or SCSS code.
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
The best way to install M4Assets is with RubyGems:
|
14
|
+
|
15
|
+
$ [sudo] gem install m4assets
|
16
|
+
|
17
|
+
Or add it to your Gemfile:
|
18
|
+
|
19
|
+
gem 'm4assets'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle install
|
24
|
+
|
25
|
+
If you're installing from source, you can use Bundler to pick up all the gems,
|
26
|
+
including those required for running the tests and creating coverage reports:
|
27
|
+
|
28
|
+
$ bundle install
|
29
|
+
|
30
|
+
Consult the online documentation for more information on
|
31
|
+
{Bundler}[http://gembundler.com/]
|
32
|
+
|
33
|
+
== Dependencies
|
34
|
+
|
35
|
+
* {Sprockets}[http://github.com/sstephenson/sprockets]
|
36
|
+
|
37
|
+
== Getting started
|
38
|
+
|
39
|
+
M4Assets uses +which+ to configure itself. You may, however, override the
|
40
|
+
auto-detected location of the m4 binary:
|
41
|
+
|
42
|
+
M4Assets.configure do |config|
|
43
|
+
config.path = "/path/to/m4"
|
44
|
+
end
|
45
|
+
|
46
|
+
Next you need to register M4Assets. If you are using Rails and you want to
|
47
|
+
use m4 macros in your JavaScript code, you would create the following
|
48
|
+
initializer:
|
49
|
+
|
50
|
+
Rails.application.assets.register_preprocessor 'application/javascript',
|
51
|
+
M4Assets::Processor
|
52
|
+
|
53
|
+
== Contributing
|
54
|
+
|
55
|
+
If you'd like to contribute to Tweedle, start by forking the repo on GitHub:
|
56
|
+
|
57
|
+
{http://github.com/tobiassvn/m4assets}[http://github.com/tobiassvn/m4assets]
|
58
|
+
|
59
|
+
To get all of the dependencies, install the gem first. The best way to
|
60
|
+
getyour changes merged back into core is as follows:
|
61
|
+
|
62
|
+
* Clone down your fork.
|
63
|
+
* Create a thoughtfully named topic branch to contain your change.
|
64
|
+
* Hack away.
|
65
|
+
* Add tests and make sure everything still passes by running rake.
|
66
|
+
* If you are adding new functionality, document it in the README.
|
67
|
+
* Do not change the version number, I will do that on my end.
|
68
|
+
* If necessary, rebase your commits into logical chunks, without errors
|
69
|
+
* Push the branch up to GitHub
|
70
|
+
* Send a pull request to the tobiassvn/m4assets project.
|
71
|
+
|
72
|
+
== License
|
73
|
+
|
74
|
+
Copyright (c) 2012 Tobias Svensson.
|
75
|
+
|
76
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
77
|
+
of this software and associated documentation files (the "Software"), to deal
|
78
|
+
in the Software without restriction, including without limitation the rights
|
79
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
80
|
+
copies of the Software, and to permit persons to whom the Software is
|
81
|
+
furnished to do so, subject to the following conditions:
|
82
|
+
|
83
|
+
The above copyright notice and this permission notice shall be included in
|
84
|
+
all copies or substantial portions of the Software.
|
85
|
+
|
86
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
87
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
88
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
89
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
90
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
91
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
92
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module M4Assets
|
2
|
+
class Processor < Sprockets::Processor
|
3
|
+
def evaluate(context, locals)
|
4
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(M4Assets.config.path)
|
5
|
+
stdin.puts(data)
|
6
|
+
stdin.close
|
7
|
+
|
8
|
+
# Exit status is 0 for success, 1 for failure, 63 for frozen file version
|
9
|
+
# mismatch, or whatever value was passed to the m4exit macro.
|
10
|
+
if exitstatus = wait_thr.value.exitstatus != 0
|
11
|
+
raise Error.new("m4 exit status #{exitstatus}. stderr: #{stderr.read}")
|
12
|
+
end
|
13
|
+
|
14
|
+
# Trim dangling newline.
|
15
|
+
stdout.read[0..-2]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/m4assets.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'sprockets'
|
2
|
+
require 'open3'
|
3
|
+
require 'm4assets/version'
|
4
|
+
require 'm4assets/error'
|
5
|
+
require 'm4assets/processor'
|
6
|
+
|
7
|
+
module M4Assets
|
8
|
+
class << self
|
9
|
+
attr_writer :config
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield config
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
@config ||= OpenStruct.new(path: `which m4`)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/m4assets.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'm4assets/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "m4assets"
|
8
|
+
gem.version = M4Assets::VERSION
|
9
|
+
gem.authors = ["Tobias Svensson"]
|
10
|
+
gem.email = ["tob@tobiassvensson.co.uk"]
|
11
|
+
gem.description = "Sprockets support for the M4 preprocessor"
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = "http://github.com/tobiassvn/m4assets"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "sprockets"
|
21
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_config.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class TestConfig < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@old_config = M4Assets.config.dup
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
M4Assets.config = @old_config
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_configure
|
13
|
+
M4Assets.configure do |config|
|
14
|
+
config.path = 'foo'
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal M4Assets.config.path, 'foo'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class TestProcessor < MiniTest::Unit::TestCase
|
4
|
+
class Context
|
5
|
+
attr_accessor :logical_path
|
6
|
+
|
7
|
+
def initialize(lpath)
|
8
|
+
@logical_path = lpath
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def context
|
13
|
+
Context.new('/assets/javascripts/test.coffee.m4')
|
14
|
+
end
|
15
|
+
|
16
|
+
def process(string)
|
17
|
+
processor = M4Assets::Processor.new { string }
|
18
|
+
processor.evaluate(context, {})
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_empty_data
|
22
|
+
assert_equal '', process('')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_string
|
26
|
+
assert_equal 'test', process('test')
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_macro
|
30
|
+
assert_equal '5', process('incr(4)')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_error_handling
|
34
|
+
assert_raises(M4Assets::Error) do
|
35
|
+
process('m4exit(1)')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m4assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tobias Svensson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sprockets
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Sprockets support for the M4 preprocessor
|
31
|
+
email:
|
32
|
+
- tob@tobiassvensson.co.uk
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.rdoc
|
41
|
+
- Rakefile
|
42
|
+
- lib/m4assets.rb
|
43
|
+
- lib/m4assets/error.rb
|
44
|
+
- lib/m4assets/processor.rb
|
45
|
+
- lib/m4assets/version.rb
|
46
|
+
- m4assets.gemspec
|
47
|
+
- test/helper.rb
|
48
|
+
- test/test_config.rb
|
49
|
+
- test/test_processor.rb
|
50
|
+
homepage: http://github.com/tobiassvn/m4assets
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.23
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Sprockets support for the M4 preprocessor
|
74
|
+
test_files:
|
75
|
+
- test/helper.rb
|
76
|
+
- test/test_config.rb
|
77
|
+
- test/test_processor.rb
|