sprockets-foo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "ext/sprockets_with_directives"]
2
+ path = ext/sprockets_with_directives
3
+ url = http://github.com/sstephenson/sprockets.git
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ben Curren
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = sprockets-foo
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Ben Curren. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sprockets-foo"
8
+ gem.summary = %Q{Enhancements for sprockets including templating support with ejs.}
9
+ gem.description = %Q{Enhancements for sprockets including templating support with ejs.}
10
+ gem.email = "ben@outright.com"
11
+ gem.homepage = "http://github.com/bcurren/sprockets-foo"
12
+ gem.authors = ["Ben Curren"]
13
+ gem.add_dependency "ejs-rcompiler", ">= 0.1.1"
14
+ # gem.add_dependency "sprockets", ">= " # use when sprockets directive branch is merged
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "sprockets-foo #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,6 @@
1
+
2
+ # TODO: When this branch is merged into master and released as a gem, update the gem
3
+ # dependencies and remove the submodule. This is only temporarily needed.
4
+ require "#{File.dirname(__FILE__)}/../ext/sprockets_with_directives/lib/sprockets.rb"
5
+
6
+ require "#{File.dirname(__FILE__)}/sprockets/directives/template_directive"
@@ -0,0 +1,36 @@
1
+ require "ejs-rcompiler"
2
+
3
+ module Sprockets
4
+ module Directives
5
+ class TemplateDirective < RequireDirective
6
+ def self.pattern
7
+ /(template)\s+(#{ANGLED_STRING})/
8
+ end
9
+
10
+ def evaluate_in(preprocessor)
11
+ compile_ejs
12
+ super(preprocessor)
13
+ end
14
+
15
+ protected
16
+
17
+ def compile_ejs
18
+ compiler = Ejs::Compiler.new
19
+ compiler.compile(template_file_path.to_s, namespace)
20
+ end
21
+
22
+ def namespace
23
+ dir = File.dirname(require_location)
24
+ dir == "." ? nil : dir.gsub(/\//, ".")
25
+ end
26
+
27
+ def template_file_path
28
+ @template_file_path ||= location_finder.find(normalize_template(require_location))
29
+ end
30
+
31
+ def normalize_template(location)
32
+ File.join(File.dirname(location), File.basename(location, ".ejs") + ".ejs")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ var before_template;
2
+ //= template <MyTemplate>
3
+ var after_template;
@@ -0,0 +1,3 @@
1
+ var before_template;
2
+ //= template <or/ui/MyNamespacedTemplate>
3
+ var after_template;
@@ -0,0 +1 @@
1
+ <p>Content</p>
@@ -0,0 +1,11 @@
1
+ // Autogenerated from an Ejs file. Edits may be lost.
2
+
3
+
4
+ window.MyTemplate = window.MyTemplate || {};
5
+ MyTemplate.template = function(options) {
6
+ var p = [];
7
+ with(options) {
8
+ p.push('<p>Content</p>\n');
9
+ }
10
+ return p.join('');
11
+ }
@@ -0,0 +1 @@
1
+ <p>Content</p>
@@ -0,0 +1,13 @@
1
+ // Autogenerated from an Ejs file. Edits may be lost.
2
+
3
+
4
+ window.or = window.or || {};
5
+ window.or.ui = window.or.ui || {};
6
+ window.or.ui.MyNamespacedTemplate = window.or.ui.MyNamespacedTemplate || {};
7
+ or.ui.MyNamespacedTemplate.template = function(options) {
8
+ var p = [];
9
+ with(options) {
10
+ p.push('<p>Content</p>\n');
11
+ }
12
+ return p.join('');
13
+ }
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require "#{File.dirname(__FILE__)}/../lib/sprockets-foo"
3
+ require "test/unit"
4
+
5
+ class Test::Unit::TestCase
6
+ FIXTURES_PATH = File.expand_path(File.join(File.dirname(__FILE__), "fixtures")) unless defined?(FIXTURES_PATH)
7
+
8
+ protected
9
+ def environment_for_fixtures
10
+ Sprockets::Environment.new(FIXTURES_PATH, source_directories_in_fixtures_path)
11
+ end
12
+
13
+ def source_directories_in_fixtures_path
14
+ Dir[File.join(FIXTURES_PATH, "**", "src")]
15
+ end
16
+ end
@@ -0,0 +1,93 @@
1
+ require "test_helper"
2
+
3
+ class PreprocessorTest < Test::Unit::TestCase
4
+ def setup
5
+ @environment = environment_for_fixtures
6
+ @preprocessor = Sprockets::Preprocessor.new(@environment, :strip_comments => false)
7
+ end
8
+
9
+ def test_requiring_a_template_with_namespace_should_compile_then_require
10
+ require_file_for_this_test
11
+ assert_concatenation_contains <<-LINES
12
+ var before_template;
13
+ // Autogenerated from an Ejs file. Edits may be lost.
14
+
15
+
16
+ window.or = window.or || {};
17
+ window.or.ui = window.or.ui || {};
18
+ window.or.ui.MyNamespacedTemplate = window.or.ui.MyNamespacedTemplate || {};
19
+ or.ui.MyNamespacedTemplate.template = function(options) {
20
+ var p = [];
21
+ with(options) {
22
+ p.push('<p>Content</p>\\n');
23
+ }
24
+ return p.join('');
25
+ }
26
+ var after_template;
27
+ LINES
28
+ end
29
+
30
+ def test_requiring_a_template_should_compile_then_require
31
+ require_file_for_this_test
32
+ assert_concatenation_contains <<-LINES
33
+ var before_template;
34
+ // Autogenerated from an Ejs file. Edits may be lost.
35
+
36
+
37
+ window.MyTemplate = window.MyTemplate || {};
38
+ MyTemplate.template = function(options) {
39
+ var p = [];
40
+ with(options) {
41
+ p.push('<p>Content</p>\\n');
42
+ }
43
+ return p.join('');
44
+ }
45
+ var after_template;
46
+ LINES
47
+ end
48
+
49
+ protected
50
+
51
+ attr_reader :environment, :preprocessor
52
+
53
+ def require_file_for_this_test
54
+ require_file(file_for_this_test)
55
+ end
56
+
57
+ def require_file(location)
58
+ preprocessor.require(environment.find(location).source_file)
59
+ end
60
+
61
+ def assert_concatenation_contains(indented_text)
62
+ lines = indented_text.split($/)
63
+ initial_indent = lines.first[/^\s*/].length
64
+ unindented_text = lines.map { |line| line[initial_indent..-1] }.join($/)
65
+ output_text[unindented_text]
66
+
67
+ assert output_text[unindented_text]
68
+ end
69
+
70
+ def assert_concatenation_contains_line(line)
71
+ assert source_lines_matching(line).any?, "Expected #{line.inspect} to exist"
72
+ end
73
+
74
+ def source_lines_matching(line)
75
+ concatenation.lines.select { |l| l.strip == line }
76
+ end
77
+
78
+ def concatenation
79
+ preprocessor.concatenation
80
+ end
81
+
82
+ def output_text
83
+ preprocessor.concatenation.to_s
84
+ end
85
+
86
+ def file_for_this_test
87
+ caller.map { |c| c[/`(.*?)'$/, 1] }.grep(/^test_/).first[5..-1] + ".js"
88
+ end
89
+
90
+ def assert_concatenation_does_not_contain_line(line)
91
+ assert source_lines_matching(line).empty?, "Expected #{line.inspect} not to exist"
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-foo
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Ben Curren
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-27 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ejs-rcompiler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 1
31
+ version: 0.1.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Enhancements for sprockets including templating support with ejs.
35
+ email: ben@outright.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - .gitmodules
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/sprockets-foo.rb
52
+ - lib/sprockets/directives/template_directive.rb
53
+ - test/fixtures/requiring_a_template_should_compile_then_require.js
54
+ - test/fixtures/requiring_a_template_with_namespace_should_compile_then_require.js
55
+ - test/fixtures/src/MyTemplate.ejs
56
+ - test/fixtures/src/MyTemplate.js
57
+ - test/fixtures/src/or/ui/MyNamespacedTemplate.ejs
58
+ - test/fixtures/src/or/ui/MyNamespacedTemplate.js
59
+ - test/test_helper.rb
60
+ - test/test_preprocessor.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/bcurren/sprockets-foo
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.6
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Enhancements for sprockets including templating support with ejs.
91
+ test_files:
92
+ - test/test_helper.rb
93
+ - test/test_preprocessor.rb