adamh-html_namespacing 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -183,7 +183,7 @@ files, if you are using <tt>html_namespacing_javascript_tag()</tt>. For
183
183
  instance, if <tt>:javascript_optional_suffix</tt> is <tt>'compressed'</tt> and
184
184
  you rendered the partial <tt>app/views/foos/_foo.html.haml</tt>, then the
185
185
  (presumably minified) file
186
- <tt>app/javascripts/views/foos/_foo.compressed.js</tt> will be included if it
186
+ <tt>app/javascripts/views/foos/_foo.js.compressed</tt> will be included if it
187
187
  exists (otherwise the standard <tt>app/javascripts/views/foos/_foo.js</tt>,
188
188
  otherwise nothing).
189
189
 
@@ -251,7 +251,7 @@ reader.
251
251
 
252
252
  Use the following Rails helper, possibly in your default layout:
253
253
 
254
- <tt>html_namespacing_javascript_tag(:jquery)</tt>
254
+ html_namespacing_javascript_tag(:jquery)
255
255
 
256
256
  Afterwards, similar to our namespaced CSS framework above, you can easily
257
257
  namespace JavaScript behavior:
@@ -271,6 +271,18 @@ available: <tt>NS</tt>, the namespace string, and <tt>$NS()</tt>, a function
271
271
  returning a jQuery object containing all elements at the root of the
272
272
  namespace.)
273
273
 
274
+ In a more complex setup, you may prefer to add another extension, like so:
275
+
276
+ html_namespacing_javascript_tag(:jquery, :format => :mobile)
277
+
278
+ This will find <tt>app/javascripts/views/foos/_description.mobile.js</tt> and
279
+ will ignore <tt>app/javascripts/views/foos/_description.js</tt>. Neglecting the
280
+ second parameter, <tt>html_namespacing_javascript_tag()</tt> would include
281
+ <tt>_description.js</tt> and <em>exclude</em> <tt>_description.mobile.js</tt>:
282
+ only single-extension JavaScript will be included. To include both, use:
283
+
284
+ html_namespacing_javascript_tag(:jquery, :format => [nil, :mobile])
285
+
274
286
  === Caching and JavaScript Namespacing
275
287
 
276
288
  Caching throws a wrench into operations.
@@ -36,14 +36,17 @@ module HtmlNamespacing
36
36
  end
37
37
 
38
38
  module Helpers
39
- def html_namespacing_javascript_tag(framework)
40
- files = html_namespacing_files
39
+ def html_namespacing_javascript_tag(framework, options = {})
40
+ files = html_namespacing_files(options[:format])
41
+ root = Pathname.new(::HtmlNamespacing::Plugin::Rails.javascript_root)
42
+
41
43
  unless files.empty?
42
44
  r = "<script type=\"text/javascript\"><!--//--><![CDATA[//><!--\n"
43
45
  r << HtmlNamespaceJs[framework][:top]
44
46
  r << "\n"
45
- files.collect do |relative_path, absolute_path|
46
- r << html_namespacing_inline_js(framework, relative_path, absolute_path)
47
+ files.collect do |path|
48
+ relative_path = Pathname.new(path).relative_path_from(root)
49
+ r << html_namespacing_inline_js(framework, relative_path.to_s, path)
47
50
  r << "\n"
48
51
  end
49
52
  r << "//--><!]]></script>"
@@ -54,40 +57,25 @@ module HtmlNamespacing
54
57
 
55
58
  HtmlNamespaceJs = {
56
59
  :jquery => {
57
- :top => File.open(File.join(File.dirname(__FILE__), 'dom_scan_jquery.compressed.js')) { |f| f.read },
60
+ :top => File.open(File.join(File.dirname(__FILE__), 'dom_scan_jquery.js.compressed')) { |f| f.read },
58
61
  :each => 'jQuery(function($){var NS=%s,$NS=function(){return $($.NS[NS]||[])};%s});'
59
62
  }
60
63
  }
61
64
 
62
- def html_namespacing_files
63
- suffix = ::HtmlNamespacing::Plugin::Rails.javascript_optional_suffix
64
- root = ::HtmlNamespacing::Plugin::Rails.javascript_root
65
-
66
- r = html_namespacing_rendered_paths
67
-
68
- r.uniq!
69
-
70
- r.collect! do |relative_path|
71
- prefix = File.join(root, relative_path)
72
- absolute_path = "#{prefix}.js"
73
- absolute_path_with_suffix = "#{prefix}.#{suffix}.js" if suffix
74
-
75
- if suffix && File.exist?(absolute_path_with_suffix)
76
- [relative_path, absolute_path_with_suffix]
77
- elsif File.exist?(absolute_path)
78
- [relative_path, absolute_path]
79
- else
80
- nil
81
- end
65
+ def html_namespacing_files(format)
66
+ (Array === format ? format : [format]).inject([]) do |r, f|
67
+ r.concat(GlobFu.find(
68
+ html_namespacing_rendered_paths,
69
+ :suffix => 'js',
70
+ :extra_suffix => f && f.to_s,
71
+ :optional_suffix => ::HtmlNamespacing::Plugin::Rails.javascript_optional_suffix,
72
+ :root => ::HtmlNamespacing::Plugin::Rails.javascript_root
73
+ ))
82
74
  end
83
-
84
- r.compact!
85
-
86
- r
87
75
  end
88
76
 
89
77
  def html_namespacing_inline_js(framework, relative_path, absolute_path)
90
- namespace = ::HtmlNamespacing::Plugin::Rails.path_to_namespace(relative_path)
78
+ namespace = ::HtmlNamespacing::Plugin::Rails.path_to_namespace(relative_path.sub(/\..*$/, ''))
91
79
  content = File.open(absolute_path) { |f| f.read }
92
80
 
93
81
  HtmlNamespaceJs[framework][:each] % [namespace.to_json, content]
@@ -1,24 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/test_helper'
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
- class CExtensionTest < Test::Unit::TestCase
5
+ describe(HtmlNamespacing) do
6
6
  private
7
7
 
8
8
  def self.define_test(name, html, ns, expect)
9
- define_method("test_#{name}".to_sym) do
10
- assert_equal(expect, f(html, ns))
9
+ it("should work with #{name}") do
10
+ f(html, ns).should == expect
11
11
  end
12
12
  end
13
13
 
14
14
  def self.define_failing_test(name, html)
15
- define_method("test_#{name}".to_sym) do
16
- assert_raises(ArgumentError) do
17
- f(html, 'X')
18
- end
15
+ it("should fail on #{name}") do
16
+ lambda { f(html, 'X') }.should raise_error(ArgumentError)
19
17
  end
20
18
  end
21
19
 
20
+ def f(html, ns)
21
+ HtmlNamespacing::add_namespace_to_html(html, ns)
22
+ end
23
+
22
24
  self.define_test('nil HTML', nil, 'X', nil)
23
25
  self.define_test('nil namespace', '<div>hello</div>', nil, '<div>hello</div>')
24
26
  self.define_test('nil everything', nil, nil, nil)
@@ -45,11 +47,7 @@ class CExtensionTest < Test::Unit::TestCase
45
47
  self.define_test("ignores <#{tag}> tags", "<#{tag}>foo</#{tag}>", "X", "<#{tag}>foo</#{tag}>")
46
48
  end
47
49
 
48
- self.define_failing_test('unclosed tag fails', '<div>foo')
49
- self.define_failing_test('closing tag fails', 'foo</div>')
50
- self.define_failing_test('wrong attr syntax fails', '<div foo=bar>foo</div>')
51
-
52
- def f(html, ns)
53
- HtmlNamespacing::add_namespace_to_html(html, ns)
54
- end
50
+ self.define_failing_test('unclosed tag', '<div>foo')
51
+ self.define_failing_test('closing tag', 'foo</div>')
52
+ self.define_failing_test('wrong attr syntax', '<div foo=bar>foo</div>')
55
53
  end
@@ -1,3 +1,4 @@
1
- require 'test/unit'
1
+ require 'rubygems'
2
+ require 'spec'
2
3
 
3
4
  require File.dirname(__FILE__) + '/../lib/html_namespacing'
metadata CHANGED
@@ -1,18 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adamh-html_namespacing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
- - Adam Hooper
7
+ - adamh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-17 00:00:00 -07:00
12
+ date: 2009-08-19 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: adamh-glob_fu
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.3
24
+ version:
16
25
  description: Inserts "class=" attributes within snippets of HTML so CSS and JavaScript can use automatic scopes
17
26
  email: adam@adamhooper.com
18
27
  executables: []
@@ -22,36 +31,24 @@ extensions:
22
31
  extra_rdoc_files:
23
32
  - README.rdoc
24
33
  files:
25
- - README.rdoc
26
- - Rakefile
27
- - test/c_extension_test.rb
28
- - test/test_helper.rb
29
- - ext/html_namespacing/extconf.rb
30
- - ext/html_namespacing/html_namespacing.h
31
34
  - ext/html_namespacing/html_namespacing.c
35
+ - ext/html_namespacing/html_namespacing.h
32
36
  - ext/html_namespacing/html_namespacing_ext.c
33
37
  - lib/html_namespacing.rb
34
38
  - lib/html_namespacing/plugin.rb
35
- - lib/html_namespacing/plugin/dom_scan_jquery.compressed.js
36
- - lib/html_namespacing/plugin/rails.rb
37
39
  - lib/html_namespacing/plugin/dom_scan_jquery.js
40
+ - lib/html_namespacing/plugin/dom_scan_jquery.js.compressed
41
+ - lib/html_namespacing/plugin/rails.rb
38
42
  - lib/html_namespacing/plugin/sass.rb
39
- - html_namespacing.gemspec
40
- - Manifest
43
+ - README.rdoc
41
44
  has_rdoc: true
42
45
  homepage: http://github.com/adamh/html_namespacing
43
46
  licenses:
44
47
  post_install_message:
45
48
  rdoc_options:
46
- - --line-numbers
47
- - --inline-source
48
- - --title
49
- - Html_namespacing
50
- - --main
51
- - README.rdoc
49
+ - --charset=UTF-8
52
50
  require_paths:
53
51
  - lib
54
- - ext
55
52
  required_ruby_version: !ruby/object:Gem::Requirement
56
53
  requirements:
57
54
  - - ">="
@@ -62,15 +59,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
59
  requirements:
63
60
  - - ">="
64
61
  - !ruby/object:Gem::Version
65
- version: "1.2"
62
+ version: "0"
66
63
  version:
67
64
  requirements: []
68
65
 
69
- rubyforge_project: html_namespacing
66
+ rubyforge_project:
70
67
  rubygems_version: 1.3.5
71
68
  signing_key:
72
69
  specification_version: 2
73
70
  summary: Automatic HTML namespacing
74
71
  test_files:
75
- - test/c_extension_test.rb
76
- - test/test_helper.rb
72
+ - spec/c_extension_spec.rb
73
+ - spec/spec_helper.rb
data/Manifest DELETED
@@ -1,16 +0,0 @@
1
- README.rdoc
2
- Rakefile
3
- test/c_extension_test.rb
4
- test/test_helper.rb
5
- ext/html_namespacing/extconf.rb
6
- ext/html_namespacing/html_namespacing.h
7
- ext/html_namespacing/html_namespacing.c
8
- ext/html_namespacing/html_namespacing_ext.c
9
- lib/html_namespacing.rb
10
- lib/html_namespacing/plugin.rb
11
- lib/html_namespacing/plugin/dom_scan_jquery.compressed.js
12
- lib/html_namespacing/plugin/rails.rb
13
- lib/html_namespacing/plugin/dom_scan_jquery.js
14
- lib/html_namespacing/plugin/sass.rb
15
- html_namespacing.gemspec
16
- Manifest
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
4
-
5
- Echoe.new('html_namespacing', '0.1.3') do |p|
6
- p.author = 'Adam Hooper'
7
- p.email = 'adam@adamhooper.com'
8
- p.summary = 'Automatic HTML namespacing'
9
- p.description = 'Inserts "class=" attributes within snippets of HTML so CSS and JavaScript can use automatic scopes'
10
- p.url = 'http://github.com/adamh/html_namespacing'
11
- p.rdoc_files = ['README.rdoc'] # echoe seems to gather everything twice
12
- end
@@ -1,33 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{html_namespacing}
5
- s.version = "0.1.3"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Adam Hooper"]
9
- s.date = %q{2009-08-17}
10
- s.description = %q{Inserts "class=" attributes within snippets of HTML so CSS and JavaScript can use automatic scopes}
11
- s.email = %q{adam@adamhooper.com}
12
- s.extensions = ["ext/html_namespacing/extconf.rb"]
13
- s.extra_rdoc_files = ["README.rdoc"]
14
- s.files = ["README.rdoc", "Rakefile", "test/c_extension_test.rb", "test/test_helper.rb", "ext/html_namespacing/extconf.rb", "ext/html_namespacing/html_namespacing.h", "ext/html_namespacing/html_namespacing.c", "ext/html_namespacing/html_namespacing_ext.c", "lib/html_namespacing.rb", "lib/html_namespacing/plugin.rb", "lib/html_namespacing/plugin/dom_scan_jquery.compressed.js", "lib/html_namespacing/plugin/rails.rb", "lib/html_namespacing/plugin/dom_scan_jquery.js", "lib/html_namespacing/plugin/sass.rb", "html_namespacing.gemspec", "Manifest"]
15
- s.has_rdoc = true
16
- s.homepage = %q{http://github.com/adamh/html_namespacing}
17
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Html_namespacing", "--main", "README.rdoc"]
18
- s.require_paths = ["lib", "ext"]
19
- s.rubyforge_project = %q{html_namespacing}
20
- s.rubygems_version = %q{1.3.1}
21
- s.summary = %q{Automatic HTML namespacing}
22
- s.test_files = ["test/c_extension_test.rb", "test/test_helper.rb"]
23
-
24
- if s.respond_to? :specification_version then
25
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
- s.specification_version = 2
27
-
28
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
- else
30
- end
31
- else
32
- end
33
- end