rails_react_stdio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc304e414a2fa5ed1a07398b7132a47ec6976525
4
+ data.tar.gz: 309d5b4fcbfbf758e416a50107c5ac729e70a124
5
+ SHA512:
6
+ metadata.gz: ba88b2c7347ecd4fbbbd6df1959338b0dd6411f390aa50b1a69feb913f0429ed29c0447b8e5bf0cde8662e0080906dd3fd898337db13cfadf1a6845ea8a198c5
7
+ data.tar.gz: 7e674f19eb6eaf8d3623ee0588e2157314932bcf51c7bd91bcaad3d863c1247e6c06abecab04f2323136d1cc831878fceee3d4bea7484c84571836d851fea5f8
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # rails_react_stdio
2
+
3
+ ## 0.0.1 (January 31, 2016)
4
+ #### New Features
5
+ - Accepts a config file to manually set path to rails_react_stdio
6
+ - Added basic tests
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 Aaron Van Bokhoven
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # rails_react_stdio
2
+
3
+ This is a simple rails wrapper for [react-stdio](https://github.com/mjackson/react-stdio).
4
+
5
+ ## Installation
6
+ Add `rails_react_stdio` to your gemfile:
7
+
8
+ ```ruby
9
+ gem 'rails_react_stdio', '~> 0.1.0'
10
+ ```
11
+
12
+ If your path to react-stdio is not installed in the default location `/usr/local/bin/react-stdio`, add a configuration file to your initializers folder.
13
+
14
+ ```ruby
15
+ RailsReactStdio.configure do |config|
16
+ config.react_stdio_path = '/your/path/to/react-stdio'
17
+ end
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ Using rails_react_stdio is very simple. You just need to provide a location to your component file, and any props you wish to pass to it as a hash.
23
+
24
+ ```ruby
25
+ path_to_component = ::Rails.application.assets['components/HelloWorld'].filename
26
+
27
+ RailsReactStdio::React.render(path_to_component, {message: "aaron"})
28
+
29
+ > "<p data-reactid=\".1on4o1jtdds\" data-react-checksum=\"359665029\">Hello, aaron</p>"
30
+ ```
@@ -0,0 +1,3 @@
1
+ require 'rails_react_stdio/configuration'
2
+ require 'rails_react_stdio/version'
3
+ require 'rails_react_stdio/react'
@@ -0,0 +1,20 @@
1
+ module RailsReactStdio
2
+ def self.configure
3
+ yield(configuration)
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new(
8
+ react_stdio_path: '/usr/local/bin/react-stdio'
9
+ )
10
+ end
11
+
12
+ # Configuration Class
13
+ class Configuration
14
+ attr_accessor :react_stdio_path
15
+
16
+ def initialize(react_stdio_path: nil)
17
+ self.react_stdio_path = react_stdio_path
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'json'
2
+ require 'open3'
3
+ module RailsReactStdio
4
+ class React
5
+ class << self
6
+ def render(component_path, props)
7
+ react_stdio_hash = { component: component_path, props: props }
8
+ react_stdio_json = react_stdio_hash.to_json
9
+ results = open_stdio(react_stdio_json)
10
+ results_hash = JSON.parse(results)
11
+ parse_stdout(results_hash)
12
+ end
13
+
14
+ private
15
+
16
+ def open_stdio(json)
17
+ stdin, stdout =
18
+ Open3.popen3(RailsReactStdio.configuration.react_stdio_path)
19
+ stdin.puts(json)
20
+ stdin.close
21
+ stdout.gets
22
+ end
23
+
24
+ def parse_stdout(results)
25
+ if results['error']
26
+ return results['error']
27
+ elsif results['html']
28
+ return results['html']
29
+ end
30
+ 'Error sending stdin to react-stdio.'
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module RailsReactStdio
2
+ VERSION = "0.1.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_react_stdio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Van Bokhoven
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest-reporters
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.7
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda-context
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Use react-stdio in your Ruby on Rails app.
56
+ email:
57
+ - bokhoven@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE
64
+ - README.md
65
+ - lib/rails_react_stdio.rb
66
+ - lib/rails_react_stdio/configuration.rb
67
+ - lib/rails_react_stdio/react.rb
68
+ - lib/rails_react_stdio/version.rb
69
+ homepage: https://github.com/aaronvb/rails_react_stdio
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.4.5.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Rails wrapper for react-stdio.
93
+ test_files: []
94
+ has_rdoc: