reactive-ruby 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +30 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +53 -0
- data/LICENSE +19 -0
- data/README.md +303 -0
- data/config.ru +15 -0
- data/example/examples/Gemfile +7 -0
- data/example/examples/Gemfile.lock +45 -0
- data/example/examples/config.ru +44 -0
- data/example/examples/hello.js.rb +43 -0
- data/example/react-tutorial/Gemfile +7 -0
- data/example/react-tutorial/Gemfile.lock +49 -0
- data/example/react-tutorial/README.md +8 -0
- data/example/react-tutorial/_comments.json +14 -0
- data/example/react-tutorial/config.ru +63 -0
- data/example/react-tutorial/example.js.rb +290 -0
- data/example/react-tutorial/public/base.css +62 -0
- data/example/todos/Gemfile +11 -0
- data/example/todos/Gemfile.lock +84 -0
- data/example/todos/README.md +37 -0
- data/example/todos/Rakefile +8 -0
- data/example/todos/app/application.rb +22 -0
- data/example/todos/app/components/app.react.rb +61 -0
- data/example/todos/app/components/footer.react.rb +31 -0
- data/example/todos/app/components/todo_item.react.rb +46 -0
- data/example/todos/app/components/todo_list.react.rb +25 -0
- data/example/todos/app/models/todo.rb +19 -0
- data/example/todos/config.ru +14 -0
- data/example/todos/index.html.haml +16 -0
- data/example/todos/spec/todo_spec.rb +28 -0
- data/example/todos/vendor/base.css +410 -0
- data/example/todos/vendor/bg.png +0 -0
- data/example/todos/vendor/jquery.js +4 -0
- data/lib/rails-helpers/react_component.rb +32 -0
- data/lib/reactive-ruby.rb +23 -0
- data/lib/reactive-ruby/api.rb +177 -0
- data/lib/reactive-ruby/callbacks.rb +35 -0
- data/lib/reactive-ruby/component.rb +411 -0
- data/lib/reactive-ruby/element.rb +87 -0
- data/lib/reactive-ruby/event.rb +76 -0
- data/lib/reactive-ruby/ext/hash.rb +9 -0
- data/lib/reactive-ruby/ext/string.rb +8 -0
- data/lib/reactive-ruby/isomorphic_helpers.rb +223 -0
- data/lib/reactive-ruby/observable.rb +33 -0
- data/lib/reactive-ruby/rendering_context.rb +91 -0
- data/lib/reactive-ruby/serializers.rb +15 -0
- data/lib/reactive-ruby/state.rb +90 -0
- data/lib/reactive-ruby/top_level.rb +53 -0
- data/lib/reactive-ruby/validator.rb +83 -0
- data/lib/reactive-ruby/version.rb +3 -0
- data/logo1.png +0 -0
- data/logo2.png +0 -0
- data/logo3.png +0 -0
- data/reactive-ruby.gemspec +25 -0
- data/spec/callbacks_spec.rb +107 -0
- data/spec/component_spec.rb +597 -0
- data/spec/element_spec.rb +60 -0
- data/spec/event_spec.rb +22 -0
- data/spec/react_spec.rb +209 -0
- data/spec/reactjs/index.html.erb +11 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/tutorial/tutorial_spec.rb +37 -0
- data/spec/validator_spec.rb +79 -0
- data/vendor/active_support/core_ext/array/extract_options.rb +29 -0
- data/vendor/active_support/core_ext/class/attribute.rb +127 -0
- data/vendor/active_support/core_ext/kernel/singleton_class.rb +13 -0
- data/vendor/active_support/core_ext/module/remove_method.rb +11 -0
- metadata +205 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
class Hash
|
2
|
+
# By default, only instances of Hash itself are extractable.
|
3
|
+
# Subclasses of Hash may implement this method and return
|
4
|
+
# true to declare themselves as extractable. If a Hash
|
5
|
+
# is extractable, Array#extract_options! pops it from
|
6
|
+
# the Array when it is the last element of the Array.
|
7
|
+
def extractable_options?
|
8
|
+
instance_of?(Hash)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Array
|
13
|
+
# Extracts options from a set of arguments. Removes and returns the last
|
14
|
+
# element in the array if it's a hash, otherwise returns a blank hash.
|
15
|
+
#
|
16
|
+
# def options(*args)
|
17
|
+
# args.extract_options!
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# options(1, 2) # => {}
|
21
|
+
# options(1, 2, :a => :b) # => {:a=>:b}
|
22
|
+
def extract_options!
|
23
|
+
if last.is_a?(Hash) && last.extractable_options?
|
24
|
+
pop
|
25
|
+
else
|
26
|
+
{}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'active_support/core_ext/kernel/singleton_class'
|
2
|
+
require 'active_support/core_ext/module/remove_method'
|
3
|
+
require 'active_support/core_ext/array/extract_options'
|
4
|
+
|
5
|
+
class Class
|
6
|
+
# Declare a class-level attribute whose value is inheritable by subclasses.
|
7
|
+
# Subclasses can change their own value and it will not impact parent class.
|
8
|
+
#
|
9
|
+
# class Base
|
10
|
+
# class_attribute :setting
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# class Subclass < Base
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Base.setting = true
|
17
|
+
# Subclass.setting # => true
|
18
|
+
# Subclass.setting = false
|
19
|
+
# Subclass.setting # => false
|
20
|
+
# Base.setting # => true
|
21
|
+
#
|
22
|
+
# In the above case as long as Subclass does not assign a value to setting
|
23
|
+
# by performing <tt>Subclass.setting = _something_ </tt>, <tt>Subclass.setting</tt>
|
24
|
+
# would read value assigned to parent class. Once Subclass assigns a value then
|
25
|
+
# the value assigned by Subclass would be returned.
|
26
|
+
#
|
27
|
+
# This matches normal Ruby method inheritance: think of writing an attribute
|
28
|
+
# on a subclass as overriding the reader method. However, you need to be aware
|
29
|
+
# when using +class_attribute+ with mutable structures as +Array+ or +Hash+.
|
30
|
+
# In such cases, you don't want to do changes in places but use setters:
|
31
|
+
#
|
32
|
+
# Base.setting = []
|
33
|
+
# Base.setting # => []
|
34
|
+
# Subclass.setting # => []
|
35
|
+
#
|
36
|
+
# # Appending in child changes both parent and child because it is the same object:
|
37
|
+
# Subclass.setting << :foo
|
38
|
+
# Base.setting # => [:foo]
|
39
|
+
# Subclass.setting # => [:foo]
|
40
|
+
#
|
41
|
+
# # Use setters to not propagate changes:
|
42
|
+
# Base.setting = []
|
43
|
+
# Subclass.setting += [:foo]
|
44
|
+
# Base.setting # => []
|
45
|
+
# Subclass.setting # => [:foo]
|
46
|
+
#
|
47
|
+
# For convenience, an instance predicate method is defined as well.
|
48
|
+
# To skip it, pass <tt>instance_predicate: false</tt>.
|
49
|
+
#
|
50
|
+
# Subclass.setting? # => false
|
51
|
+
#
|
52
|
+
# Instances may overwrite the class value in the same way:
|
53
|
+
#
|
54
|
+
# Base.setting = true
|
55
|
+
# object = Base.new
|
56
|
+
# object.setting # => true
|
57
|
+
# object.setting = false
|
58
|
+
# object.setting # => false
|
59
|
+
# Base.setting # => true
|
60
|
+
#
|
61
|
+
# To opt out of the instance reader method, pass <tt>instance_reader: false</tt>.
|
62
|
+
#
|
63
|
+
# object.setting # => NoMethodError
|
64
|
+
# object.setting? # => NoMethodError
|
65
|
+
#
|
66
|
+
# To opt out of the instance writer method, pass <tt>instance_writer: false</tt>.
|
67
|
+
#
|
68
|
+
# object.setting = false # => NoMethodError
|
69
|
+
#
|
70
|
+
# To opt out of both instance methods, pass <tt>instance_accessor: false</tt>.
|
71
|
+
def class_attribute(*attrs)
|
72
|
+
options = attrs.extract_options!
|
73
|
+
instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
|
74
|
+
instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
|
75
|
+
instance_predicate = options.fetch(:instance_predicate, true)
|
76
|
+
|
77
|
+
attrs.each do |name|
|
78
|
+
define_singleton_method(name) { nil }
|
79
|
+
define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
|
80
|
+
|
81
|
+
ivar = "@#{name}"
|
82
|
+
|
83
|
+
define_singleton_method("#{name}=") do |val|
|
84
|
+
singleton_class.class_eval do
|
85
|
+
remove_possible_method(name)
|
86
|
+
define_method(name) { val }
|
87
|
+
end
|
88
|
+
|
89
|
+
if singleton_class?
|
90
|
+
class_eval do
|
91
|
+
remove_possible_method(name)
|
92
|
+
define_method(name) do
|
93
|
+
if instance_variable_defined? ivar
|
94
|
+
instance_variable_get ivar
|
95
|
+
else
|
96
|
+
singleton_class.send name
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
val
|
102
|
+
end
|
103
|
+
|
104
|
+
if instance_reader
|
105
|
+
remove_possible_method name
|
106
|
+
define_method(name) do
|
107
|
+
if instance_variable_defined?(ivar)
|
108
|
+
instance_variable_get ivar
|
109
|
+
else
|
110
|
+
self.class.public_send name
|
111
|
+
end
|
112
|
+
end
|
113
|
+
define_method("#{name}?") { !!public_send(name) } if instance_predicate
|
114
|
+
end
|
115
|
+
|
116
|
+
attr_writer name if instance_writer
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
unless respond_to?(:singleton_class?)
|
123
|
+
def singleton_class?
|
124
|
+
ancestors.first != self
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Kernel
|
2
|
+
# Returns the object's singleton class.
|
3
|
+
def singleton_class
|
4
|
+
class << self
|
5
|
+
self
|
6
|
+
end
|
7
|
+
end unless respond_to?(:singleton_class) # exists in 1.9.2
|
8
|
+
|
9
|
+
# class_eval on an object acts like singleton_class.class_eval.
|
10
|
+
def class_eval(*args, &block)
|
11
|
+
singleton_class.class_eval(*args, &block)
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reactive-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Chang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: opal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: opal-activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: react-source
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: opal-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: opal-jquery
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Write reactive UI component with Ruby's elegancy and compiled to run
|
98
|
+
in Javascript.
|
99
|
+
email: zeta11235813@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- config.ru
|
110
|
+
- example/examples/Gemfile
|
111
|
+
- example/examples/Gemfile.lock
|
112
|
+
- example/examples/config.ru
|
113
|
+
- example/examples/hello.js.rb
|
114
|
+
- example/react-tutorial/Gemfile
|
115
|
+
- example/react-tutorial/Gemfile.lock
|
116
|
+
- example/react-tutorial/README.md
|
117
|
+
- example/react-tutorial/_comments.json
|
118
|
+
- example/react-tutorial/config.ru
|
119
|
+
- example/react-tutorial/example.js.rb
|
120
|
+
- example/react-tutorial/public/base.css
|
121
|
+
- example/todos/Gemfile
|
122
|
+
- example/todos/Gemfile.lock
|
123
|
+
- example/todos/README.md
|
124
|
+
- example/todos/Rakefile
|
125
|
+
- example/todos/app/application.rb
|
126
|
+
- example/todos/app/components/app.react.rb
|
127
|
+
- example/todos/app/components/footer.react.rb
|
128
|
+
- example/todos/app/components/todo_item.react.rb
|
129
|
+
- example/todos/app/components/todo_list.react.rb
|
130
|
+
- example/todos/app/models/todo.rb
|
131
|
+
- example/todos/config.ru
|
132
|
+
- example/todos/index.html.haml
|
133
|
+
- example/todos/spec/todo_spec.rb
|
134
|
+
- example/todos/vendor/base.css
|
135
|
+
- example/todos/vendor/bg.png
|
136
|
+
- example/todos/vendor/jquery.js
|
137
|
+
- lib/rails-helpers/react_component.rb
|
138
|
+
- lib/reactive-ruby.rb
|
139
|
+
- lib/reactive-ruby/api.rb
|
140
|
+
- lib/reactive-ruby/callbacks.rb
|
141
|
+
- lib/reactive-ruby/component.rb
|
142
|
+
- lib/reactive-ruby/element.rb
|
143
|
+
- lib/reactive-ruby/event.rb
|
144
|
+
- lib/reactive-ruby/ext/hash.rb
|
145
|
+
- lib/reactive-ruby/ext/string.rb
|
146
|
+
- lib/reactive-ruby/isomorphic_helpers.rb
|
147
|
+
- lib/reactive-ruby/observable.rb
|
148
|
+
- lib/reactive-ruby/rendering_context.rb
|
149
|
+
- lib/reactive-ruby/serializers.rb
|
150
|
+
- lib/reactive-ruby/state.rb
|
151
|
+
- lib/reactive-ruby/top_level.rb
|
152
|
+
- lib/reactive-ruby/validator.rb
|
153
|
+
- lib/reactive-ruby/version.rb
|
154
|
+
- logo1.png
|
155
|
+
- logo2.png
|
156
|
+
- logo3.png
|
157
|
+
- reactive-ruby.gemspec
|
158
|
+
- spec/callbacks_spec.rb
|
159
|
+
- spec/component_spec.rb
|
160
|
+
- spec/element_spec.rb
|
161
|
+
- spec/event_spec.rb
|
162
|
+
- spec/react_spec.rb
|
163
|
+
- spec/reactjs/index.html.erb
|
164
|
+
- spec/spec_helper.rb
|
165
|
+
- spec/tutorial/tutorial_spec.rb
|
166
|
+
- spec/validator_spec.rb
|
167
|
+
- vendor/active_support/core_ext/array/extract_options.rb
|
168
|
+
- vendor/active_support/core_ext/class/attribute.rb
|
169
|
+
- vendor/active_support/core_ext/kernel/singleton_class.rb
|
170
|
+
- vendor/active_support/core_ext/module/remove_method.rb
|
171
|
+
homepage: https://github.com/zetachang/react.rb
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata: {}
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
- vendor
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
requirements: []
|
191
|
+
rubyforge_project:
|
192
|
+
rubygems_version: 2.4.8
|
193
|
+
signing_key:
|
194
|
+
specification_version: 4
|
195
|
+
summary: Opal Ruby wrapper of React.js library.
|
196
|
+
test_files:
|
197
|
+
- spec/callbacks_spec.rb
|
198
|
+
- spec/component_spec.rb
|
199
|
+
- spec/element_spec.rb
|
200
|
+
- spec/event_spec.rb
|
201
|
+
- spec/react_spec.rb
|
202
|
+
- spec/reactjs/index.html.erb
|
203
|
+
- spec/spec_helper.rb
|
204
|
+
- spec/tutorial/tutorial_spec.rb
|
205
|
+
- spec/validator_spec.rb
|