html_namespacing 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -221,7 +221,12 @@ add_namespace_to_html_with_length_and_allocation_strategy(
221
221
  } \
222
222
  } while (0)/*;*/
223
223
  #define ADVANCE_UNTIL_ONE_OF_THESE_CHARS(chars) \
224
- ADVANCE(strcspn(html_p, chars))/*;*/
224
+ do { \
225
+ const size_t num_chars = strcspn(html_p, chars); \
226
+ ADVANCE(num_chars); \
227
+ if (*html_p == '\0') \
228
+ goto end; \
229
+ } while (0) /*;*/
225
230
 
226
231
  unsigned int state;
227
232
  char *r; /* Start of retval */
@@ -385,6 +390,7 @@ add_namespace_to_html_with_length_and_allocation_strategy(
385
390
  }
386
391
  }
387
392
 
393
+ end:
388
394
  COPY_TO_HERE();
389
395
  APPEND_END_OF_STRING();
390
396
 
@@ -34,29 +34,83 @@ module HtmlNamespacing
34
34
  @options[:javascript_root] || RAILS_ROOT + '/app/javascripts/views'
35
35
  end
36
36
 
37
+ def self.stylesheet_root
38
+ @options[:stylesheet_root] || RAILS_ROOT + '/app/stylesheets/views'
39
+ end
40
+
37
41
  def self.javascript_optional_suffix
38
42
  @options[:javascript_optional_suffix]
39
43
  end
40
44
 
45
+ def self.stylesheet_optional_suffix
46
+ @options[:stylesheet_optional_suffix]
47
+ end
48
+
41
49
  def self.template_formats
42
50
  @formats ||= Set.new(@options[:template_formats] || ['html'])
43
51
  end
44
52
 
45
53
  module Helpers
54
+ #
55
+ # Return the javascript for the rendered partials, wrapped in
56
+ # a script tag.
57
+ #
46
58
  def html_namespacing_javascript_tag(framework, options = {})
47
- files = html_namespacing_files(options[:format])
48
- root = Pathname.new(::HtmlNamespacing::Plugin::Rails.javascript_root)
59
+ js = html_namespacing_javascript(framework, options)
60
+ unless js.blank?
61
+ "<script type=\"text/javascript\"><!--//--><![CDATA[//><!--\n#{js}//--><!]]></script>"
62
+ end
63
+ end
49
64
 
65
+ #
66
+ # Return the javascript for the rendered partials.
67
+ #
68
+ def html_namespacing_javascript(framework, options = {})
69
+ root = Pathname.new(Rails.javascript_root)
70
+ optional_suffix = Rails.javascript_optional_suffix
71
+ files = html_namespacing_files('js',
72
+ :format => options[:format],
73
+ :optional_suffix => optional_suffix,
74
+ :root => root.to_s)
50
75
  unless files.empty?
51
- r = "<script type=\"text/javascript\"><!--//--><![CDATA[//><!--\n"
52
- r << HtmlNamespaceJs[framework][:top]
53
- r << "\n"
54
- files.collect do |path|
76
+ r = [HtmlNamespaceJs[framework][:top]] << "\n"
77
+ files.each do |path|
55
78
  relative_path = Pathname.new(path).relative_path_from(root)
56
- r << html_namespacing_inline_js(framework, relative_path.to_s, path)
57
- r << "\n"
79
+ r << html_namespacing_inline_js(framework, relative_path.to_s, path) << "\n"
58
80
  end
59
- r << "//--><!]]></script>"
81
+ r.join
82
+ end
83
+ end
84
+
85
+ #
86
+ # Return the CSS for the rendered partials, wrapped in a style
87
+ # tag.
88
+ #
89
+ def html_namespacing_style_tag(options = {}, style_tag_attributes = {})
90
+ css = html_namespacing_styles(options)
91
+ unless css.blank?
92
+ attribute_string = style_tag_attributes.map{|k,v| " #{k}=\"#{v}\""}.join
93
+ "<style type=\"text/css\"#{attribute_string}>#{css}</style>"
94
+ end
95
+ end
96
+
97
+ #
98
+ # Return the CSS for the rendered partials.
99
+ #
100
+ def html_namespacing_styles(options = {})
101
+ root = Pathname.new(Rails.stylesheet_root)
102
+ optional_suffix = Rails.stylesheet_optional_suffix
103
+ files = html_namespacing_files('sass',
104
+ :format => options[:format],
105
+ :optional_suffix => optional_suffix,
106
+ :root => root.to_s)
107
+ unless files.empty?
108
+ r = []
109
+ files.each do |path|
110
+ relative_path = Pathname.new(path).relative_path_from(root)
111
+ r << html_namespacing_inline_css(relative_path.to_s, path)
112
+ end
113
+ r.join
60
114
  end
61
115
  end
62
116
 
@@ -69,14 +123,15 @@ module HtmlNamespacing
69
123
  }
70
124
  }
71
125
 
72
- def html_namespacing_files(format)
126
+ def html_namespacing_files(suffix, options={})
127
+ format = options[:format]
73
128
  (Array === format ? format : [format]).inject([]) do |r, f|
74
129
  r.concat(GlobFu.find(
75
130
  html_namespacing_rendered_paths,
76
- :suffix => 'js',
131
+ :suffix => suffix,
77
132
  :extra_suffix => f && f.to_s,
78
- :optional_suffix => ::HtmlNamespacing::Plugin::Rails.javascript_optional_suffix,
79
- :root => ::HtmlNamespacing::Plugin::Rails.javascript_root
133
+ :optional_suffix => options[:optional_suffix],
134
+ :root => options[:root]
80
135
  ))
81
136
  end
82
137
  end
@@ -87,6 +142,10 @@ module HtmlNamespacing
87
142
 
88
143
  HtmlNamespaceJs[framework][:each] % [namespace.to_json, content]
89
144
  end
145
+
146
+ def html_namespacing_inline_css(relative_path, absolute_path)
147
+ HtmlNamespacing.options[:styles_for].call(relative_path, absolute_path)
148
+ end
90
149
  end
91
150
 
92
151
  private
@@ -1,10 +1,27 @@
1
1
  module HtmlNamespacing
2
2
  module Plugin
3
3
  module Sass
4
- def self.install(options = {})
5
- options[:prefix] ||= 'views'
6
- options[:callback] ||= lambda { |p| HtmlNamespacing::Plugin.default_relative_path_to_namespace(p) }
7
- Sass_2_2.install(options)
4
+ class << self
5
+ def install(options = {})
6
+ options[:prefix] ||= 'views'
7
+ options[:callback] ||= lambda { |p| HtmlNamespacing::Plugin.default_relative_path_to_namespace(p) }
8
+ options[:compress] ||= false
9
+ @options = options
10
+ Sass_2_2.install(options)
11
+ HtmlNamespacing.options[:styles_for] = method(:styles_for)
12
+ end
13
+
14
+ attr_reader :options
15
+
16
+ def sass_options
17
+ ::Sass::Plugin.options
18
+ end
19
+
20
+ def styles_for(relative_path, absolute_path)
21
+ # Assume the file exists. (If it was found by GlobFu, it should.)
22
+ css_path = File.join(sass_options[:css_location], self.options[:prefix], relative_path.sub(/\.[^\.\/]*\z/, '.css'))
23
+ File.read(css_path)
24
+ end
8
25
  end
9
26
 
10
27
  module Sass_2_2
@@ -46,7 +63,7 @@ module HtmlNamespacing
46
63
  end
47
64
 
48
65
  def namespacing_regex
49
- /^#{Regexp.quote(options[:css_location])}\/#{Regexp.quote(namespacing_prefix)}\/(.*)\.css$/
66
+ /^#{Regexp.quote(Sass.sass_options[:css_location])}\/#{Regexp.quote(namespacing_prefix)}\/(.*)\.css$/
50
67
  end
51
68
 
52
69
  def namespace
@@ -2,4 +2,8 @@ require File.dirname(__FILE__) + '/../ext/html_namespacing/html_namespacing_ext'
2
2
 
3
3
  module HtmlNamespacing
4
4
  autoload(:Plugin, File.dirname(__FILE__) + '/html_namespacing/plugin')
5
+
6
+ def self.options
7
+ @options ||= {}
8
+ end
5
9
  end
@@ -52,4 +52,7 @@ describe(HtmlNamespacing) do
52
52
  self.define_failing_test('unclosed tag', '<div>foo')
53
53
  self.define_failing_test('closing tag', 'foo</div>')
54
54
  self.define_failing_test('wrong attr syntax', '<div foo=bar>foo</div>')
55
+ self.define_failing_test("missing closing '>' on last tag", '<div foo="bar">foo</div')
56
+ self.define_failing_test('end of string during attribute value', '<div foo="x')
57
+ self.define_failing_test('end of string during doctype declaration', '<!DOCTYPE')
55
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_namespacing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - adamh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-16 00:00:00 -05:00
12
+ date: 2010-01-30 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency