rwr-view_helpers 0.0.1 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08a6e7fbb37224a088343a6830530b9f42b87232
4
- data.tar.gz: 4f45fbc8ccdee714c61c7d3f20b0a1f12f2629d7
3
+ metadata.gz: 6de7639bd92e58b65f00515ddbc9b690190299a3
4
+ data.tar.gz: b9a0b3cbc70c366cf75e8d440db855cfa1e11b5f
5
5
  SHA512:
6
- metadata.gz: f8cf7729e13c6ea7cdf79ca80ebdb97418188b04f5347d366bf70c1d9839ecef76a379254c7b402c10f32cd07355d1eb9f4b9a18afd28ba6a3241298de9806be
7
- data.tar.gz: a1e23dc9059bd5ad3a05472cc6ff1d367c5571c3a2385cfa589ccb7eb41494cf5dec89e82c5e4819a67b537d574a377e8d30373653edc2b6c1ccee53b07e207d
6
+ metadata.gz: 1e5e7e326d6d7440efa628998aa5e48b487886b77978d5c25a6cf726d6f7f2f6e76936727048d4875579dde1775f2ab24a85241b1e680d93b9a996dc1b383859
7
+ data.tar.gz: 2eb246dfa73700e128c6d961fc5695e0fa8bc2d52490b4a52fcc68a0b8138644372e0723f5b5604b596e147f402b1cc0f6feff4f5cfc35786246d0c8c9c05662
data/.travis.yml CHANGED
@@ -24,8 +24,8 @@ cache:
24
24
  matrix:
25
25
  include:
26
26
  - rvm: 2.2.4
27
- gemfile: spec/test-app/Gemfile
28
- env: TEST_SUITE=test-app
27
+ gemfile: spec/rails4_dummy_app/Gemfile
28
+ env: TEST_SUITE=rails4
29
29
  - rvm: 2.2.4
30
30
  gemfile: Gemfile
31
31
  env: TEST_SUITE=gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.2.0
2
+ - implemented support for server-side rendering
3
+
4
+ ## 0.1.0
5
+ - implemented helper to access rails image assets directly from Javascript
data/Rakefile CHANGED
@@ -1,7 +1,57 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ namespace :test do
5
+ desc 'Run all tests'
6
+ task all: [:node, :gem, :rails4] do
7
+ puts 'Finished all tests, yay!'
8
+ end
9
+
10
+ desc 'Run node package tests'
11
+ task :node do
12
+ sh %Q(npm test)
13
+ end
14
+
15
+ desc 'Run gem tests'
16
+ task :gem do
17
+ sh %Q(bundle exec rspec spec)
18
+ end
19
+
20
+ desc 'Run rspec for rails4 application'
21
+ task :rails4 do
22
+ Bundler.with_clean_env do
23
+ sh %Q(
24
+ cd spec/rails4_dummy_app &&
25
+ npm run build &&
26
+ npm run rwr-background-node &&
27
+ sleep 4 &&
28
+ bundle exec rspec &&
29
+ npm run rwr-stop-background-node
30
+ )
31
+ end
32
+ end
5
33
  end
6
34
 
7
- Bundler::GemHelper.install_tasks
35
+ task default: 'test:all'
36
+
37
+ namespace :setup do
38
+ desc 'Prepare every environment'
39
+ task all: [:node, :gem, :rails4] do
40
+ puts 'Prepared all, yay!'
41
+ end
42
+
43
+ desc 'Prepare node module dependencies'
44
+ task :node do
45
+ sh %Q(npm install)
46
+ end
47
+
48
+ desc 'Prepare gem dependencies'
49
+ task :gem do
50
+ sh %Q(bundle install)
51
+ end
52
+
53
+ desc 'Prepare rails4 test app dependencies'
54
+ task :rails4 do
55
+ sh %Q(npm install && cd spec/rails4_dummy_app && npm install && bundle install)
56
+ end
57
+ end
data/js/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.0.1';
1
+ export default '0.1.0';
@@ -1,5 +1,6 @@
1
1
  (function(global) {
2
2
  global.__RWR_VIEW_HELPERS__ = {
3
3
  imagePaths: <%= ReactWebpackRails::RWRViewHelpers::ImagePaths.fetch.to_json %>,
4
+ version: '<%= ReactWebpackRails::RWRViewHelpers::VERSION %>',
4
5
  };
5
6
  })(window);
@@ -8,7 +8,6 @@ module ReactWebpackRails
8
8
  @include = ['*.gif', '*.jpg', '*.jpeg', '*.png']
9
9
 
10
10
  def self.fetch
11
- puts "-------------------------- FETCH ---------------------------"
12
11
  project_assets = {}
13
12
  env = Sprockets::Railtie.build_environment(::Rails.application)
14
13
 
@@ -26,6 +25,11 @@ module ReactWebpackRails
26
25
  )
27
26
  end
28
27
 
28
+ Dir.mkdir(::Rails.root.join('tmp', 'cache')) unless File.exists?(::Rails.root.join('tmp', 'cache'))
29
+ open(::Rails.root.join('tmp', 'cache', 'assets-mapping.json'), 'w') do |file|
30
+ file.write project_assets.to_json
31
+ end
32
+
29
33
  return project_assets
30
34
  end
31
35
  end
@@ -1,5 +1,5 @@
1
1
  module ReactWebpackRails
2
2
  module RWRViewHelpers
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -1,3 +1,6 @@
1
- require 'react_webpack_rails/rwr_view_helpers/rails/engine'
2
- require 'react_webpack_rails/rwr_view_helpers/image_paths'
3
1
  require 'react_webpack_rails/rwr_view_helpers/version'
2
+
3
+ if defined?(Rails)
4
+ require 'react_webpack_rails/rwr_view_helpers/rails/engine'
5
+ require 'react_webpack_rails/rwr_view_helpers/image_paths'
6
+ end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwr-view-helpers",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "ReactWebpackRails integration with useful view helpers.",
5
5
  "main": "js/lib/index.js",
6
6
  "files": [
@@ -19,10 +19,12 @@ Gem::Specification.new do |s|
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = Dir["test/**/*"]
21
21
 
22
- s.add_dependency 'react_webpack_rails', '>= 0.1.0'
22
+ s.add_dependency 'react_webpack_rails', '>= 0.5.0'
23
23
  s.add_dependency 'rails'
24
24
  s.add_dependency 'sprockets', '>= 3.0'
25
25
 
26
26
  s.add_development_dependency 'bundler', '~> 1.10'
27
+ s.add_development_dependency 'rspec', '~> 3.3'
28
+ s.add_development_dependency 'rake', '~> 10.0'
27
29
  s.add_development_dependency "yard"
28
30
  end
@@ -115,8 +115,8 @@ rerun.txt
115
115
  pickle-email-*.html
116
116
 
117
117
  # TODO Comment out these rules if you are OK with secrets being uploaded to the repo
118
- config/initializers/secret_token.rb
119
- config/secrets.yml
118
+ # config/initializers/secret_token.rb
119
+ # config/secrets.yml
120
120
 
121
121
  ## Environment normalisation:
122
122
  /.bundle
@@ -0,0 +1,49 @@
1
+ require('babel-core/register');
2
+ require('./index');
3
+
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const http = require('http');
7
+ const dispatcher = require('httpdispatcher');
8
+ const { integrationsManager } = require('react-webpack-rails');
9
+
10
+ const PORT = 8081;
11
+ const ASSETS_MAPPING_PATH = 'tmp/cache/assets-mapping.json';
12
+
13
+ global.__RWR_ENV__ = {};
14
+ global.__RWR_VIEW_HELPERS__ = { imagePaths: {} };
15
+
16
+ fs.readFile(ASSETS_MAPPING_PATH, (err, data) => {
17
+ if (err) { return err; }
18
+ const imagePaths = data.toString('utf-8');
19
+ global.__RWR_VIEW_HELPERS__.imagePaths = JSON.parse(imagePaths);
20
+ });
21
+
22
+ const handleRequest = (req, res) => {
23
+ const { method, url } = req;
24
+ const reqStartTime = (new Date()).toLocaleTimeString();
25
+
26
+ console.log(`${method} "${url}" - ${reqStartTime}`);
27
+ dispatcher.dispatch(req, res);
28
+ }
29
+
30
+ dispatcher.onPost('/run', (req, res) => {
31
+ try {
32
+ const data = JSON.parse(req.body);
33
+ const result = integrationsManager.runNodeIntegration(data);
34
+
35
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
36
+ res.end(result);
37
+ } catch(e) {
38
+ console.error(e);
39
+
40
+ res.writeHead(500);
41
+ res.end(`nodeRun failed:\n ${e.name}: ${e.message}`);
42
+ }
43
+ });
44
+
45
+ http
46
+ .createServer(handleRequest)
47
+ .listen(PORT, () => {
48
+ console.log(`Server listening on: http://localhost:${PORT}`)
49
+ });
@@ -1,7 +1,7 @@
1
- <h1> Original Spongebob </h1>
1
+ <h1> Original Spongebob, rendered on server </h1>
2
2
 
3
- <%= react_component('Spongebob', { server_side: false }) %>
3
+ <%= react_component('Spongebob', {}, server_side: true) %>
4
4
 
5
5
  <h1> Spongebob with size passed as prop from Rails View </h1>
6
6
 
7
- <%= react_component('Spongebob', { size: 2 }, { server_side: false }) %>
7
+ <%= react_component('Spongebob', { size: 2 }, server_side: false) %>
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 87fb945fc5e4bbcc51eccc2687818b1f0b00ca4e6ce973263f65585b2d82ba8c58a5c73a08cc868d708dc54137a15db13e89e4c8d59d34a8e3a32865d020ee29
15
+
16
+ test:
17
+ secret_key_base: 7295e7eb84648c8d1ecd414f984ee32148afb18f5610c8c321f24b2b5bef489e90782012b11d6666a0358e116e85efae2f54a4e58dd161c4f4fd873e45f1a9cb
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -3,6 +3,7 @@
3
3
  "append": true,
4
4
  "script": "node_server.js",
5
5
  "sourceDir": "./app/react",
6
+ "workingDir": ".",
6
7
  "watch": true,
7
8
  "watchDirectory": "./app/react"
8
9
  }
@@ -2,5 +2,6 @@
2
2
  "uid": "rwr-node-server",
3
3
  "append": true,
4
4
  "script": "node_server.js",
5
- "sourceDir": "./app/react"
5
+ "sourceDir": "./app/react",
6
+ "workingDir": "."
6
7
  }
@@ -46,6 +46,8 @@
46
46
  "rwr-node-server": "forever -o log/rwr-server-out.log -e log/rwr-server-err.log forever/production.json",
47
47
  "start": "webpack -w --config webpack/dev.config.js",
48
48
  "start-hot-dev": "webpack-dev-server --hot --inline --config webpack/hot-dev.config.js",
49
+ "rwr-background-node": "forever start -o log/rwr-server-out.log -e log/rwr-server-err.log forever/production.json",
50
+ "rwr-stop-background-node": "forever stopall",
49
51
  "test": "mocha --no-colors app/react/test/helpers/browser.js app/react/**/*.spec.js"
50
52
  },
51
53
  "license": "MIT",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rwr-view_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oskar Cieslik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-12 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: react_webpack_rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: yard
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +119,7 @@ files:
91
119
  - ".eslintrc"
92
120
  - ".gitignore"
93
121
  - ".travis.yml"
122
+ - CHANGELOG.md
94
123
  - CONTRIBUTING.md
95
124
  - Gemfile
96
125
  - LICENSE
@@ -108,15 +137,6 @@ files:
108
137
  - lib/rwr-view_helpers.rb
109
138
  - package.json
110
139
  - rwr-view_helpers.gemspec
111
- - rwr-view_helpers/.gitignore
112
- - rwr-view_helpers/Gemfile
113
- - rwr-view_helpers/README.md
114
- - rwr-view_helpers/Rakefile
115
- - rwr-view_helpers/bin/console
116
- - rwr-view_helpers/bin/setup
117
- - rwr-view_helpers/lib/rwr/view_helpers.rb
118
- - rwr-view_helpers/lib/rwr/view_helpers/version.rb
119
- - rwr-view_helpers/rwr-view_helpers.gemspec
120
140
  - spec/rails4_dummy_app/.babelrc
121
141
  - spec/rails4_dummy_app/.gitignore
122
142
  - spec/rails4_dummy_app/.nvmrc
@@ -138,6 +158,7 @@ files:
138
158
  - spec/rails4_dummy_app/app/react/components/Spongebob.js
139
159
  - spec/rails4_dummy_app/app/react/components/Spongebob.spec.js
140
160
  - spec/rails4_dummy_app/app/react/index.js
161
+ - spec/rails4_dummy_app/app/react/node_server.js
141
162
  - spec/rails4_dummy_app/app/react/test/helpers/browser.js
142
163
  - spec/rails4_dummy_app/app/views/layouts/_react_hot_assets.html.erb
143
164
  - spec/rails4_dummy_app/app/views/layouts/application.html.erb
@@ -165,6 +186,7 @@ files:
165
186
  - spec/rails4_dummy_app/config/initializers/wrap_parameters.rb
166
187
  - spec/rails4_dummy_app/config/locales/en.yml
167
188
  - spec/rails4_dummy_app/config/routes.rb
189
+ - spec/rails4_dummy_app/config/secrets.yml
168
190
  - spec/rails4_dummy_app/db/schema.rb
169
191
  - spec/rails4_dummy_app/db/seeds.rb
170
192
  - spec/rails4_dummy_app/forever/development.json
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in rwr-view_helpers.gemspec
4
- gemspec
@@ -1,36 +0,0 @@
1
- # Rwr::ViewHelpers
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rwr/view_helpers`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'rwr-view_helpers'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install rwr-view_helpers
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rwr-view_helpers.
36
-
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rwr/view_helpers"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,5 +0,0 @@
1
- module Rwr
2
- module ViewHelpers
3
- VERSION = "0.1.0"
4
- end
5
- end
@@ -1,7 +0,0 @@
1
- require "rwr/view_helpers/version"
2
-
3
- module Rwr
4
- module ViewHelpers
5
- # Your code goes here...
6
- end
7
- end
@@ -1,31 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rwr/view_helpers/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "rwr-view_helpers"
8
- spec.version = Rwr::ViewHelpers::VERSION
9
- spec.authors = ["TODO: Write your name"]
10
- spec.email = ["oskar.cieslik@netguru.pl"]
11
-
12
- spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
13
- spec.description = %q{TODO: Write a longer description or delete this line.}
14
- spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- end
23
-
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
-
29
- spec.add_development_dependency "bundler", "~> 1.12"
30
- spec.add_development_dependency "rake", "~> 10.0"
31
- end