volt 0.9.5.pre12 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e995f18c906a2379a9a631a32783910067905c19
4
- data.tar.gz: fee2b9fc14654a0a3369b72f3e3a3d315af7715b
3
+ metadata.gz: d8e569efc8f53ee1bf074fa627fe11363ecff05f
4
+ data.tar.gz: 3cbd7a15e0ff177982e46ab072ff00de7397ccc0
5
5
  SHA512:
6
- metadata.gz: ccaf2f6f632456efcb2851802d691ae992b150fe0cc84f05d8f7476cebb3b848556f18c11850052fde1a315af3d82fd4c3983c2d5bd1ba4092445451a5da3489
7
- data.tar.gz: da08f6eeef5a27ac152827cde226539718e33fb33f6b3c3cdfa2f4a8f783be86b9a7bad1a514a6170b9a83132f55fee31aa59f611915c17bf8db9b1458bd04e1
6
+ metadata.gz: 00cb9cee43f56ab6ff097bdd4ea449308927563099fb997a2f5d689c68f28e5bcf1dd03e85cf42eb6383db00ac844facce62947cd9db359bf085ca78e307ae43
7
+ data.tar.gz: c9529a9c9d50431f1756257cbfafb72f6dcf7285a1ba27990f18b2fd2cd5afb09f250a1f4236c313b898366184ab7eca255c66c625d900eeaa28b900fbe86cc9
@@ -17,7 +17,7 @@ module Volt
17
17
 
18
18
  # When writing the index, we render the
19
19
  def javascript_tags
20
- "<script async src=\"#{@volt_app.app_url}/#{@manifest['assets']['main/app.js']}\"></script>"
20
+ "<script src=\"#{@volt_app.app_url}/#{@manifest['assets']['main/app.js']}\"></script>"
21
21
  end
22
22
 
23
23
  def css_tags
@@ -83,8 +83,16 @@ module Volt
83
83
  # Multiple bindings
84
84
  add_multiple_attribute(tag_name, id, attribute_name, parts, value)
85
85
  elsif parts.size == 1 && binding_count == 1
86
- # A single binding
87
- add_single_attribute(id, attribute_name, parts)
86
+ getter = parts[0][2...-2].strip
87
+
88
+ if getter =~ /^asset_url[ \(]/
89
+ # asset url helper
90
+ add_asset_url_attribute(getter, attributes)
91
+ return # don't delete attr
92
+ else
93
+ # A single binding
94
+ add_single_attribute(id, attribute_name, getter)
95
+ end
88
96
  end
89
97
 
90
98
  # Remove the attribute
@@ -118,18 +126,26 @@ module Volt
118
126
  end
119
127
 
120
128
  # Add an attribute binding on the tag, bind directly to the getter in the binding
121
- def add_single_attribute(id, attribute_name, parts)
122
- getter = parts[0][2...-2].strip
123
-
124
- # if getter.index('@')
125
- # raise "Bindings currently do not support instance variables"
126
- # end
127
-
129
+ def add_single_attribute(id, attribute_name, getter)
128
130
  setter = getter_to_setter(getter)
129
131
 
130
132
  save_binding(id, "lambda { |__p, __t, __c, __id| Volt::AttributeBinding.new(__p, __t, __c, __id, #{attribute_name.inspect}, Proc.new { #{getter} }, Proc.new { |val| #{setter} }) }")
131
133
  end
132
134
 
135
+ def add_asset_url_attribute(getter, attributes)
136
+ # Asset url helper binding
137
+ asset_url_parts = getter.split(/[\s\(\)\'\"]/).reject(&:blank?)
138
+ url = asset_url_parts[1]
139
+
140
+ unless url
141
+ raise "the `asset_url` helper requries a url argument ```{{ asset_url 'pic.png' }}```"
142
+ end
143
+
144
+ link_url = @handler.link_asset(url, false)
145
+
146
+ attributes['src'] = link_url
147
+ end
148
+
133
149
  def add_multiple_attribute(tag_name, id, attribute_name, parts, content)
134
150
  case attribute_name
135
151
  when 'checked', 'value'
@@ -150,7 +166,7 @@ module Volt
150
166
 
151
167
  def add_string_template_renderer(content)
152
168
  path = @path + "/_rv#{@binding_number}"
153
- new_handler = ViewHandler.new(path, false)
169
+ new_handler = ViewHandler.new(path, nil, false)
154
170
  @binding_number += 1
155
171
 
156
172
  SandlebarsParser.new(content, new_handler)
@@ -1,6 +1,6 @@
1
1
  module Volt
2
2
  class ViewHandler
3
- attr_reader :templates, :scope
3
+ attr_reader :templates, :scope, :links
4
4
 
5
5
  def html
6
6
  last.html
@@ -10,8 +10,13 @@ module Volt
10
10
  @scope.last
11
11
  end
12
12
 
13
- def initialize(initial_path, allow_sections = true)
13
+ # @param [String] - the path to the template file being processed
14
+ # @param - the sprockets context, used for asset_url bindings
15
+ # @param [Boolean] - if the processing should default to body section
16
+ def initialize(initial_path, sprockets_context=nil, allow_sections = true)
14
17
  @original_path = initial_path
18
+ @sprockets_context = sprockets_context
19
+ @links = []
15
20
 
16
21
  # Default to the body section
17
22
  initial_path += '/body' if allow_sections
@@ -82,5 +87,22 @@ module Volt
82
87
  new_path = @original_path + '/' + @in_section
83
88
  @scope = [ViewScope.new(self, new_path)]
84
89
  end
90
+
91
+ # Called from the view scope when an asset_url binding is hit.
92
+ def link_asset(url, link=true)
93
+ if @sprockets_context
94
+ # Getting the asset_path also links to the context.
95
+ linked_url = @sprockets_context.asset_path(url)
96
+ else
97
+ # When compiling on the server, we don't use sprockets (atm), so the
98
+ # context won't exist. Typically compiling on the server is just used
99
+ # to test, so we simply return the url.
100
+ linked_url = url
101
+ end
102
+
103
+ last << url if link
104
+
105
+ linked_url
106
+ end
85
107
  end
86
108
  end
@@ -8,12 +8,12 @@ require 'volt/server/html_parser/textarea_scope'
8
8
 
9
9
  module Volt
10
10
  class ViewParser
11
- attr_reader :templates
11
+ attr_reader :templates, :links
12
12
 
13
- def initialize(html, template_path)
13
+ def initialize(html, template_path, sprockets_context=nil)
14
14
  @template_path = template_path
15
15
 
16
- handler = ViewHandler.new(template_path)
16
+ handler = ViewHandler.new(template_path, sprockets_context)
17
17
 
18
18
  SandlebarsParser.new(html, handler)
19
19
 
@@ -25,6 +25,7 @@ module Volt
25
25
  last_scope.close_scope
26
26
 
27
27
  @templates = handler.templates
28
+ @links = handler.links
28
29
  end
29
30
 
30
31
  # Returns a parsed version of the data (useful for backend rendering
@@ -47,6 +47,8 @@ module Volt
47
47
  add_template(args)
48
48
  when 'yield'
49
49
  add_yield(args)
50
+ when 'asset_url'
51
+ add_asset_url(args)
50
52
  else
51
53
  if content =~ /.each\s+do\s+\|/
52
54
  add_each(content, false)
@@ -71,6 +73,8 @@ module Volt
71
73
  add_content_binding(content)
72
74
  end
73
75
  end
76
+
77
+ nil
74
78
  end
75
79
 
76
80
  def add_content_binding(content)
@@ -142,6 +146,13 @@ module Volt
142
146
  @handler.last.close_scope if unary
143
147
  end
144
148
 
149
+ # The asset_url binding handles linking assets so they will be precompiled
150
+ # properly using the sprockets pipeline.
151
+ def add_asset_url(args)
152
+ # Add a link to the handler
153
+ @handler.link_asset(args.gsub(/["']/, '').strip)
154
+ end
155
+
145
156
  # Called when this scope should be closed out
146
157
  def close_scope(pop = true)
147
158
  if pop
@@ -72,7 +72,10 @@ module Volt
72
72
  Volt::ViewProcessor.setup(@environment)
73
73
 
74
74
  # Use the cached env in production so it doesn't have to stat the FS
75
- @environment = @environment.cached if Volt.env.production?
75
+ if Volt.env.production?
76
+ @environment = @environment.cached
77
+ @server.sprockets = @environment
78
+ end
76
79
 
77
80
  # Since the scope changes in builder blocks, we need to capture
78
81
  # environment in closure
@@ -35,24 +35,33 @@ module Volt
35
35
  def call(input)
36
36
  context = input[:environment].context_class.new(input)
37
37
  # context.link_asset('main/assets/images/lombard.jpg')
38
+ # puts context.asset_path('main/assets/images/lombard.jpg').inspect
38
39
  # pp input
39
40
  data = input[:data]
40
41
 
41
42
  # input[:accept] = 'application/javascript'
42
43
  # input[:content_type] = 'application/javascript'
43
44
  # input[:environment].content_type = 'application/javascript'
44
- data = input[:cache].fetch([self.cache_key, data]) do
45
+ compiled = false
46
+ data, links = input[:cache].fetch([self.cache_key, data]) do
47
+ compiled = true
45
48
  filename = input[:filename]
46
49
  # puts input[:data].inspect
47
50
  # Remove all semicolons from source
48
51
  # input[:content_type] = 'application/javascript'
49
- compile(filename, input[:data])
52
+ compile(filename, input[:data], context)
53
+ end
54
+
55
+ unless compiled
56
+ links.each do |link|
57
+ context.link_asset(link)
58
+ end
50
59
  end
51
60
 
52
61
  context.metadata.merge(data: data.to_str)
53
62
  end
54
63
 
55
- def compile(view_path, html)
64
+ def compile(view_path, html, context)
56
65
  exts = ComponentTemplates::Preprocessors.extensions
57
66
  template_path = view_path.split('/')[-4..-1].join('/').gsub('/views/', '/').gsub(/[.](#{exts.join('|')})$/, '')
58
67
 
@@ -65,10 +74,11 @@ module Volt
65
74
  if handler = ComponentTemplates.handler_for_extension(format)
66
75
  html = handler.call(html)
67
76
 
68
- code = ViewParser.new(html, template_path).code(app_reference)
77
+ parser = ViewParser.new(html, template_path, context)
78
+ code = parser.code(app_reference)
69
79
  end
70
80
 
71
- Opal.compile(code)
81
+ return [Opal.compile(code), parser.links]
72
82
  end
73
83
 
74
84
  def self.setup(sprockets=$volt_app.sprockets)
data/lib/volt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Volt
2
2
  module Version
3
- STRING = '0.9.5.pre12'
3
+ STRING = '0.9.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5.pre12
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-29 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -875,9 +875,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
875
875
  version: '2.1'
876
876
  required_rubygems_version: !ruby/object:Gem::Requirement
877
877
  requirements:
878
- - - ">"
878
+ - - ">="
879
879
  - !ruby/object:Gem::Version
880
- version: 1.3.1
880
+ version: '0'
881
881
  requirements: []
882
882
  rubyforge_project:
883
883
  rubygems_version: 2.4.5