wunderbar 0.19.1 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGRmMDMxMzI4Y2JkMWZjYjIyNjZiYzhkMzY2YjEzNjcwODhjODQxZA==
4
+ MTI3ZTFhMDA4ODRhZGQ5M2VhYjA3Yjk3ODg1NjNlMjM1NjFlMjM3OA==
5
5
  data.tar.gz: !binary |-
6
- OTAyMGVlNzBjMDllYzFlMmI2ZDgwM2ZlNzkxYzlkMTBiMmFiMWEyMQ==
6
+ NDJlZTExMzdkMDc1YzMzNjIyYzM2Y2VkYTQxZTFhZWE1YWQ0NDMzYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Mjk1MGUzMWZmZTVhMzRjOTg1OWU3YWI2ODkwNThlMWUzN2U0NzRmNGU3OGJk
10
- N2NiMzQ0MDgzYmQ3ZjIxMTk3MzNjOTMxMzdiZmMyOTdhZjJlZDNmNjhkMzA2
11
- YTg2MDllNDY3YTkzZTZiOTlhMDJmNGZmMWJjNWM0ODUwY2FlNjU=
9
+ MTBmNzJkYzVmMjMwNTdmZDA3YWQwNGRkNGFiYjJkZDE3ZTdjYWY3OWY5MjYy
10
+ NTBkOWE2NjRhYmY3OWMxZjEyODA0NTZkOWJmYjI5MTYwODQwYTkyNWZjNDYy
11
+ ZTEwOGMxMjdiNWU3NmU2MjUxNjk0NWFiN2NkZTliYTc3MDg1OTI=
12
12
  data.tar.gz: !binary |-
13
- ODM2ODg1ZjkyNDBkMjg0NDg0ODc3YTk5NTVmZjc1ZjNiMmNjODQ4ODNhYjEx
14
- YWQ0ZjczYjY3ODlhZmYzM2IxYzFlYWJiNTkxMTdlOWVkOWI4MDA4NDc5MGZh
15
- Yzk2NmZhZjllYTU4ZTZlNzY5ZTU4MGJjNGU2ZWFmODI5MzdlZTY=
13
+ ZTVkZThhNDU2N2UyMDRkYzNmY2RlZTZlYTE0OWRjNDA2M2FhMWU1MDQ0Mjcx
14
+ MjQ3MmRlMWU5M2VkOTM5ZTcyMDI0NmFkZjc0YTg5NGE3YTQ2MmRiY2Q4NDkx
15
+ MWUyMTcxNDY0ODNmOGIwNWE5MTk0ZGI3YTA4NGVlNmQyZTBlOGY=
@@ -1,11 +1,15 @@
1
1
  module Wunderbar
2
2
  class BuilderBase
3
3
  def set_variables_from_params(locals={})
4
- @_scope.params.merge(locals).each do |key,value|
4
+ params = @_scope.params.map do |key, value|
5
5
  value = value.first if Array === value
6
6
  value.gsub! "\r\n", "\n" if String === value
7
- if key =~ /^[a-z]\w+$/
8
- instance_variable_set "@#{key.dup.untaint}", value
7
+ ["@#{key}", value]
8
+ end
9
+
10
+ Hash[params].merge(locals).each do |key,value|
11
+ if key =~ /^@[a-z]\w+$/
12
+ instance_variable_set key, value
9
13
  end
10
14
  end
11
15
  end
@@ -56,6 +56,11 @@ module Wunderbar
56
56
 
57
57
  begin
58
58
  output = Ruby2JS.convert(block) + "\n"
59
+ rescue Parser::SyntaxError => exception
60
+ headers['status'] = "500 Internal Server Error"
61
+ location = exception.diagnostic.location
62
+ output = "// Syntax Error: line #{location.line}, " +
63
+ "column: #{location.column}\n#{exception}\n"
59
64
  rescue ::Exception => exception
60
65
  headers['status'] = "500 Internal Server Error"
61
66
  output = "// Internal Server Error\n#{exception}\n"
@@ -73,7 +78,12 @@ module Wunderbar
73
78
  def evaluate(scope, locals, &block)
74
79
  scope.content_type self.class.default_mime_type, charset: 'utf-8'
75
80
  begin
76
- Ruby2JS.convert(data)
81
+ Ruby2JS.convert(data, ivars: locals)
82
+ rescue Parser::SyntaxError => exception
83
+ scope.response.status = 500
84
+ location = exception.diagnostic.location
85
+ "// Syntax Error: line #{location.line}, column: #{location.column}" +
86
+ "\n#{exception}\n"
77
87
  rescue Exception => exception
78
88
  scope.response.status = 500
79
89
  "// Internal Server Error\n#{exception}\n"
@@ -11,6 +11,8 @@ end
11
11
  module Wunderbar
12
12
  module SinatraHelpers
13
13
  def _html(*args, &block)
14
+ Wunderbar::Template.locals(self, args)
15
+
14
16
  if block
15
17
  Wunderbar::Template::Html.evaluate('_html', self) do
16
18
  _html(*args) { instance_eval &block }
@@ -156,6 +158,25 @@ module Wunderbar
156
158
  end
157
159
  end
158
160
 
161
+ PASSABLE = [Numeric, String, Hash, Array]
162
+
163
+ def self.locals(scope, args)
164
+ args.push({}) if args.length == 1
165
+
166
+ return unless Hash === args.last and not args.last[:locals]
167
+
168
+ locals = {}
169
+
170
+ scope.instance_variables.each do |ivar|
171
+ next if [:@env, :@params].include? ivar
172
+ value = scope.instance_variable_get(ivar)
173
+ next unless PASSABLE.find {|klass| klass === value}
174
+ locals[ivar] = value
175
+ end
176
+
177
+ args.last[:locals] = locals
178
+ end
179
+
159
180
  def self.register(language, base=Base)
160
181
  template = Class.new(Template::Base) do
161
182
  self.default_mime_type = language.mime
@@ -163,6 +184,13 @@ module Wunderbar
163
184
  end
164
185
 
165
186
  SinatraHelpers.send :define_method, language.ext do |*args, &block|
187
+ Wunderbar::Template.locals(self, args)
188
+ if Hash === args.last and args.last[:locals]
189
+ @params.each do |name, value|
190
+ args.last[:locals]["@#{name}".to_sym] = value
191
+ end
192
+ end
193
+
166
194
  template.evaluate(language.ext, self, *args, &block)
167
195
  end
168
196
 
@@ -2,7 +2,7 @@ module Wunderbar
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 19
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/wunderbar.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "wunderbar"
5
- s.version = "0.19.1"
5
+ s.version = "0.19.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sam Ruby"]
9
- s.date = "2013-12-11"
9
+ s.date = "2013-12-18"
10
10
  s.description = " Wunderbar makes it easy to produce valid HTML5, wellformed XHTML, Unicode\n (utf-8), consistently indented, readable applications. This includes\n output that conforms to the Polyglot specification and the emerging\n results from the XML Error Recovery Community Group.\n"
11
11
  s.email = "rubys@intertwingly.net"
12
12
  s.files = ["wunderbar.gemspec", "README.md", "COPYING", "lib/wunderbar.rb", "lib/wunderbar", "lib/wunderbar/logger.rb", "lib/wunderbar/coderay.rb", "lib/wunderbar/rails.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/coffeescript.rb", "lib/wunderbar/vendor", "lib/wunderbar/vendor/polymer-v0.0.20131003.min.js", "lib/wunderbar/vendor/angular-resource.min.js", "lib/wunderbar/vendor/jquery-1.10.2.min.js", "lib/wunderbar/vendor/Markdown.Converter.js", "lib/wunderbar/vendor/angular-route.min.js", "lib/wunderbar/vendor/angular.min.js", "lib/wunderbar/vendor/stupidtable.min.js", "lib/wunderbar/markdown.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/pagedown.rb", "lib/wunderbar/server.rb", "lib/wunderbar/polymer.rb", "lib/wunderbar/version.rb", "lib/wunderbar/node.rb", "lib/wunderbar/asset.rb", "lib/wunderbar/script.rb", "lib/wunderbar/websocket.rb", "lib/wunderbar/jquery", "lib/wunderbar/jquery/stupidtable.rb", "lib/wunderbar/angularjs", "lib/wunderbar/angularjs/route.rb", "lib/wunderbar/angularjs/resource.rb", "lib/wunderbar/opal", "lib/wunderbar/opal/browser.rb", "lib/wunderbar/opal/jquery.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/cssproxy.rb", "lib/wunderbar/angularjs.rb", "lib/wunderbar/jquery.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/sinatra.rb", "lib/wunderbar/rack.rb", "lib/wunderbar/opal.rb", "lib/wunderbar/installation.rb"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wunderbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-11 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json