rbjs 0.9.15 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rbjs.rb CHANGED
@@ -1,26 +1,31 @@
1
1
  require "rbjs/version"
2
- require 'rails'
3
- require 'active_support'
4
2
  require 'json'
5
3
 
4
+ if defined?(Rails)
5
+ require 'rbjs/rails'
6
+ end
7
+
8
+ if defined?(Tilt)
9
+ require 'rbjs/tilt'
10
+ end
11
+
12
+ if defined?(Sinatra)
13
+ require 'rbjs/sinatra'
14
+ end
15
+
6
16
  module Rbjs
7
-
8
- class Railtie < Rails::Railtie
9
- initializer 'rbjs.setup' do
10
- ActiveSupport.on_load(:action_controller) do
11
- require 'rbjs/setup_action_controller'
12
- end
13
- ActiveSupport.on_load(:action_view) do
14
- require 'rbjs/setup_action_view'
15
- end
16
- end
17
- end
18
17
 
19
18
  class Root
20
19
  def initialize view_context, &block
21
20
  @_view_context = view_context and
22
- for instance_var, val in view_context.assigns
23
- instance_variable_set '@'+instance_var, val
21
+ if view_context.respond_to?(:assigns)
22
+ for instance_var, val in view_context.assigns
23
+ instance_variable_set '@'+instance_var, val
24
+ end
25
+ else
26
+ for instance_var in view_context.instance_variables.map(&:to_s)
27
+ instance_variable_set instance_var, view_context.instance_variable_get(instance_var)
28
+ end
24
29
  end
25
30
  if @_view_context.respond_to?(:helpers) && @_view_context.helpers
26
31
  extend @_view_context.helpers
data/lib/rbjs/rails.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+
3
+ module Rbjs
4
+ class Railtie < Rails::Railtie
5
+ initializer 'rbjs.setup' do
6
+ ActiveSupport.on_load(:action_controller) do
7
+ require 'rbjs/setup_action_controller'
8
+ end
9
+ ActiveSupport.on_load(:action_view) do
10
+ require 'rbjs/setup_action_view'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  ActionView::Helpers::RenderingHelper.module_eval do
3
2
  def render_with_js(options = {}, locals = {}, &block)
4
3
  if options == :js
@@ -0,0 +1,12 @@
1
+ module Rbjs
2
+ Sinatra.helpers do
3
+ def js content=nil, &block
4
+ content_type 'application/javascript'
5
+ if block_given?
6
+ render :rbjs, '', &block
7
+ else
8
+ render :rbjs, content
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/rbjs/tilt.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'tilt/template'
2
+
3
+ module Rbjs
4
+
5
+ class RbjsTemplate < Tilt::Template
6
+ self.default_mime_type = 'application/javascript'
7
+
8
+ def evaluate scope, locals, &block
9
+ return Rbjs::Root.new(scope, &block).evaluate if block_given?
10
+ super
11
+ end
12
+
13
+ def precompiled_template locals
14
+ "Rbjs::Root.new self do\n#{@data}\nend.evaluate"
15
+ end
16
+
17
+ def prepare
18
+ # Nothing to do here.
19
+ end
20
+ end
21
+
22
+ Tilt.register 'rbjs', RbjsTemplate
23
+
24
+ end
data/lib/rbjs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rbjs
2
- VERSION = "0.9.15"
2
+ VERSION = "0.10.1"
3
3
  end
data/rbjs.gemspec CHANGED
@@ -21,6 +21,6 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "rspec"
23
23
  s.add_runtime_dependency "json"
24
- s.add_runtime_dependency "rails"
25
- s.add_runtime_dependency "activesupport"
24
+ # s.add_runtime_dependency "rails"
25
+ # s.add_runtime_dependency "activesupport"
26
26
  end
metadata CHANGED
@@ -1,97 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rbjs
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.1
4
5
  prerelease:
5
- version: 0.9.15
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Stefan Buhrmester
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-11-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: json
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rails
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
16
+ requirement: &70252886637960 !ruby/object:Gem::Requirement
30
17
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
35
22
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: activesupport
39
23
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
46
- type: :runtime
47
- version_requirements: *id003
24
+ version_requirements: *70252886637960
48
25
  description: Remote Javascript Builder for Ruby on Rails
49
- email:
26
+ email:
50
27
  - buhrmi@gmail.com
51
28
  executables: []
52
-
53
29
  extensions: []
54
-
55
30
  extra_rdoc_files: []
56
-
57
- files:
31
+ files:
58
32
  - .gitignore
59
33
  - Gemfile
60
34
  - LICENSE
61
35
  - Rakefile
62
36
  - lib/rbjs.rb
37
+ - lib/rbjs/rails.rb
63
38
  - lib/rbjs/setup_action_controller.rb
64
39
  - lib/rbjs/setup_action_view.rb
40
+ - lib/rbjs/sinatra.rb
41
+ - lib/rbjs/tilt.rb
65
42
  - lib/rbjs/version.rb
66
43
  - rbjs.gemspec
67
44
  - readme.md
68
45
  - spec/rbjs_spec.rb
69
46
  homepage: http://github.com/buhrmi/rbjs
70
47
  licenses: []
71
-
72
48
  post_install_message:
73
49
  rdoc_options: []
74
-
75
- require_paths:
50
+ require_paths:
76
51
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
52
+ required_ruby_version: !ruby/object:Gem::Requirement
78
53
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
59
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
89
64
  requirements: []
90
-
91
65
  rubyforge_project: rbjs
92
- rubygems_version: 1.8.11
66
+ rubygems_version: 1.8.10
93
67
  signing_key:
94
68
  specification_version: 3
95
69
  summary: Remote Javascript re-imagined
96
- test_files:
70
+ test_files:
97
71
  - spec/rbjs_spec.rb