rails_react_components 0.1.1 → 0.1.2
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 +4 -4
- data/.rubocop.yml +25 -0
- data/.travis.yml +6 -1
- data/README.md +83 -3
- data/app/helpers/rails_react_components_helper.rb +2 -0
- data/lib/rails_react_components.rb +14 -0
- data/lib/rails_react_components/component.rb +3 -1
- data/lib/rails_react_components/components/dsl.rb +13 -1
- data/lib/rails_react_components/components/prop.rb +22 -8
- data/lib/rails_react_components/engine.rb +2 -0
- data/lib/rails_react_components/version.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 761524eb75e57ae4e5a0fa67b06e813a03ef3a3b
|
4
|
+
data.tar.gz: c12c083b9546e8b297fc69fdbbd53b9591e5eadd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8210b6d7bca769857da79e3dc3cc2bb39ab565626f88b936d154c05b038cfda2289088ff710d718c05b66c8ced6f5cb4b0bc9d05425ef5758a2a109c5c8c2b6b
|
7
|
+
data.tar.gz: 6aa61fc4d898f675982682d2a40c04ccc05c14c42af02e75d63edd43d811bbf5ad88249a6f98c3cff63aba0251e12d6c6d9b298ad96fba6f0c90cf3e830ac4c9
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- spec/**/*
|
4
|
+
- bin/**/*
|
5
|
+
- Gemfile
|
6
|
+
- Rakefile
|
7
|
+
- rails_react_components.gemspec
|
8
|
+
TargetRubyVersion: 2.4
|
9
|
+
Style/Documentation:
|
10
|
+
Description: 'Document classes and non-namespace modules.'
|
11
|
+
Enabled: false
|
12
|
+
Style/StringLiterals:
|
13
|
+
EnforcedStyle: double_quotes
|
14
|
+
SupportedStyles:
|
15
|
+
- double_quotes
|
16
|
+
Style/PercentLiteralDelimiters:
|
17
|
+
PreferredDelimiters:
|
18
|
+
default: ()
|
19
|
+
'%i': '()'
|
20
|
+
'%I': '()'
|
21
|
+
'%r': '{}'
|
22
|
+
'%w': '()'
|
23
|
+
'%W': '()'
|
24
|
+
Metrics/LineLength:
|
25
|
+
Max: 100
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,52 @@
|
|
1
1
|
# RailsReactComponents
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/Adam-Stomski/rails_react_components)
|
4
4
|
|
5
|
-
|
5
|
+
Component objects for Rails and React with `react_on_rails`
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# component class
|
9
|
+
class MyComponent < RailsReactComponents::Component
|
10
|
+
prop :name
|
11
|
+
prop :email, on: :user
|
12
|
+
prop :is_ready
|
13
|
+
prop :received_email, as: :got_email
|
14
|
+
|
15
|
+
def name
|
16
|
+
"My name is Rails Component"
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_ready
|
20
|
+
user.ready?
|
21
|
+
end
|
22
|
+
|
23
|
+
def received_email
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# in view this can run:
|
29
|
+
# react_component("MyComponent",
|
30
|
+
# props: {
|
31
|
+
# name: "My name is Rails Component",
|
32
|
+
# email: "user@example.com",
|
33
|
+
# isReady: true,
|
34
|
+
# got_email: false
|
35
|
+
# }
|
36
|
+
# )
|
37
|
+
render_react_component MyComponent, user: current_user
|
38
|
+
```
|
39
|
+
|
40
|
+
## TODO
|
41
|
+
|
42
|
+
- [ ] - nested props
|
43
|
+
- [ ] - Rspec matchers
|
44
|
+
- [x] - configuration (snake_case methods for camelCase props etc)
|
6
45
|
|
7
46
|
## Installation
|
8
47
|
|
48
|
+
If you are not using `react_on_rails` yet check https://github.com/shakacode/react_on_rails
|
49
|
+
|
9
50
|
Add this line to your application's Gemfile:
|
10
51
|
|
11
52
|
```ruby
|
@@ -20,10 +61,49 @@ Or install it yourself as:
|
|
20
61
|
|
21
62
|
$ gem install rails_react_components
|
22
63
|
|
64
|
+
## Configuration
|
65
|
+
|
66
|
+
You can add initializer (these are defaults):
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
RailsReactComponents.config do |config|
|
70
|
+
config.camelize_props = true # method :some_method will end up someMethod prop
|
71
|
+
# when true, only way to prevent this is using prop as: option
|
72
|
+
config.prerender = nil # set global prerender
|
73
|
+
config.raise_on_prerender_error = nil # set global raise_on_prerender_error
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
23
77
|
## Usage
|
24
78
|
|
25
|
-
TODO: Write usage instructions here
|
26
79
|
|
80
|
+
#### Available options example:
|
81
|
+
```ruby
|
82
|
+
class MyComponent < RailsReactComponents::Component
|
83
|
+
component "FilePicker"
|
84
|
+
|
85
|
+
id "file-picker-id"
|
86
|
+
|
87
|
+
html_option "color", "red"
|
88
|
+
html_option "opacity", "0.5"
|
89
|
+
|
90
|
+
prerender
|
91
|
+
trace
|
92
|
+
replay_console
|
93
|
+
raise_on_prerender_error
|
94
|
+
|
95
|
+
prop :blank, include_blank: false
|
96
|
+
|
97
|
+
prop :name, on: :user
|
98
|
+
prop :email, delegate: :user # alias
|
99
|
+
|
100
|
+
def blank
|
101
|
+
""
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
check also [here](spec/features) and [here](https://github.com/shakacode/react_on_rails#react_component)
|
27
107
|
|
28
108
|
## Contributing
|
29
109
|
|
@@ -1,7 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rails"
|
2
4
|
require "rails_react_components/engine"
|
3
5
|
|
4
6
|
module RailsReactComponents
|
7
|
+
mattr_accessor :camelize_props
|
8
|
+
self.camelize_props = true
|
9
|
+
|
10
|
+
mattr_accessor :prerender
|
11
|
+
self.prerender = nil
|
12
|
+
|
13
|
+
mattr_accessor :raise_on_prerender_error
|
14
|
+
self.raise_on_prerender_error = nil
|
15
|
+
|
16
|
+
def self.config
|
17
|
+
yield self
|
18
|
+
end
|
5
19
|
end
|
6
20
|
|
7
21
|
require "rails_react_components/version"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "components/prop"
|
2
4
|
require_relative "components/dsl"
|
3
5
|
|
@@ -18,7 +20,7 @@ module RailsReactComponents
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def respond_to_missing?(method_name, include_private = false)
|
21
|
-
_methods.
|
23
|
+
_methods.key?(method_name.to_sym) || super
|
22
24
|
end
|
23
25
|
|
24
26
|
def component_options
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RailsReactComponents
|
2
4
|
module Components
|
3
5
|
module Dsl
|
@@ -33,7 +35,17 @@ module RailsReactComponents
|
|
33
35
|
html_options[name] = value
|
34
36
|
end
|
35
37
|
|
36
|
-
%w(prerender
|
38
|
+
%w(prerender raise_on_prerender_error).each do |method|
|
39
|
+
define_method method do
|
40
|
+
instance_variable_set("@_#{method}", true)
|
41
|
+
end
|
42
|
+
|
43
|
+
define_method "#{method}?" do
|
44
|
+
instance_variable_get("@_#{method}") || RailsReactComponents.send(method)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
%w(trace replay_console).each do |method|
|
37
49
|
define_method method do
|
38
50
|
instance_variable_set("@_#{method}", true)
|
39
51
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RailsReactComponents
|
2
4
|
module Components
|
3
5
|
class Prop
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(name, options)
|
7
|
-
@name = name.to_sym
|
6
|
+
def initialize(method_name, options)
|
7
|
+
@method_name = method_name.to_sym
|
8
8
|
@options = options
|
9
9
|
end
|
10
10
|
|
11
11
|
def build(component)
|
12
12
|
if on.present?
|
13
|
-
component.send(on).send(
|
13
|
+
component.send(on).send(method_name)
|
14
14
|
else
|
15
|
-
component.send(
|
15
|
+
component.send(method_name)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,12 +20,26 @@ module RailsReactComponents
|
|
20
20
|
options.fetch(:include_blank, true)
|
21
21
|
end
|
22
22
|
|
23
|
+
def name
|
24
|
+
if as.present?
|
25
|
+
as
|
26
|
+
elsif RailsReactComponents.camelize_props
|
27
|
+
method_name.to_s.camelize(:lower).to_sym
|
28
|
+
else
|
29
|
+
method_name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
23
33
|
private
|
24
34
|
|
25
|
-
attr_reader :options
|
35
|
+
attr_reader :options, :method_name
|
26
36
|
|
27
37
|
def on
|
28
|
-
|
38
|
+
options[:on] || options[:delegate]
|
39
|
+
end
|
40
|
+
|
41
|
+
def as
|
42
|
+
options.fetch(:as, nil)&.to_sym
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_react_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Stomski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
92
93
|
- ".travis.yml"
|
93
94
|
- Gemfile
|
94
95
|
- LICENSE.txt
|