rails-hyperstack 1.0.alpha1
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 +48 -0
- data/.travis.yml +26 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +431 -0
- data/Rakefile +25 -0
- data/lib/generators/hyper/component_generator.rb +20 -0
- data/lib/generators/hyper/router_generator.rb +23 -0
- data/lib/generators/hyper/templates/component_template.rb +40 -0
- data/lib/generators/hyper/templates/router_template.rb +17 -0
- data/lib/generators/hyperstack/install_bootstrap_generator.rb +75 -0
- data/lib/generators/hyperstack/install_generator.rb +179 -0
- data/lib/generators/hyperstack/install_generator_base.rb +23 -0
- data/lib/generators/hyperstack/install_mui_generator.rb +54 -0
- data/lib/hyperstack/version.rb +3 -0
- data/lib/rails-hyperstack.rb +29 -0
- data/rails-hyperstack.gemspec +65 -0
- data/spec/rails_hyperstack_spec.rb +24 -0
- data/spec/spec_helper.rb +34 -0
- metadata +423 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require_relative 'install_generator_base'
|
|
2
|
+
module Hyperstack
|
|
3
|
+
class InstallBootstrapGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
desc "Adds the bits you need for the Bootstrap 3.0 framework"
|
|
6
|
+
|
|
7
|
+
class_option 'no-build', type: :boolean
|
|
8
|
+
|
|
9
|
+
def insure_yarn_loaded
|
|
10
|
+
begin
|
|
11
|
+
yarn_version = `yarn --version`
|
|
12
|
+
raise Errno::ENOENT if yarn_version.blank?
|
|
13
|
+
rescue Errno::ENOENT
|
|
14
|
+
raise Thor::Error.new("please insure the yarn command is available if using webpacker")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_to_manifests
|
|
19
|
+
add_to_manifest 'client_and_server.js' do
|
|
20
|
+
"BS = require('react-bootstrap');\n"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def add_style_sheet_pack_tag
|
|
25
|
+
inject_into_file 'app/views/layouts/application.html.erb', after: /stylesheet_link_tag.*$/ do
|
|
26
|
+
<<-JAVASCRIPT
|
|
27
|
+
|
|
28
|
+
<!-- Latest compiled and minified CSS -->
|
|
29
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
|
30
|
+
|
|
31
|
+
<!-- Optional theme -->
|
|
32
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
|
|
33
|
+
JAVASCRIPT
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def run_yarn
|
|
38
|
+
yarn 'react-bootstrap'
|
|
39
|
+
yarn 'bootstrap@3'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def build_webpack
|
|
43
|
+
system('bin/webpack') unless options['no-build']
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def add_sample_component
|
|
47
|
+
create_file 'app/hyperstack/components/bs_sampler.rb' do
|
|
48
|
+
<<-RUBY
|
|
49
|
+
class BsSampler
|
|
50
|
+
include Hyperstack::Component
|
|
51
|
+
include Hyperstack::State::Observer
|
|
52
|
+
render(DIV) do
|
|
53
|
+
BS::Grid() do
|
|
54
|
+
BS::Row(class: "show-grid") do
|
|
55
|
+
BS::Col(xs: 12, md: 8) do
|
|
56
|
+
CODE { "BS::Col(xs: 12, md: 8)" }
|
|
57
|
+
end
|
|
58
|
+
BS::Col(xs: 6, md: 4) do
|
|
59
|
+
CODE { "BS::Col(xs: 6, md: 4)" }
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
BS::Row() do
|
|
63
|
+
BS::Alert(bsStyle: "warning") do
|
|
64
|
+
STRONG { "Holy guacamole!" }
|
|
65
|
+
SPAN { " Best check yo self, you're not looking too good." }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
RUBY
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require_relative 'install_generator_base'
|
|
2
|
+
module Hyperstack
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
class_option 'skip-webpack', type: :boolean
|
|
6
|
+
class_option 'skip-hot-reloader', type: :boolean
|
|
7
|
+
class_option 'add-framework', type: :string
|
|
8
|
+
|
|
9
|
+
def insure_yarn_loaded
|
|
10
|
+
return if skip_webpack?
|
|
11
|
+
begin
|
|
12
|
+
yarn_version = `yarn --version`
|
|
13
|
+
raise Errno::ENOENT if yarn_version.blank?
|
|
14
|
+
rescue Errno::ENOENT
|
|
15
|
+
raise Thor::Error.new("please insure the yarn command is available if using webpacker")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def inject_react_file_js
|
|
20
|
+
append_file 'app/assets/javascripts/application.js' do
|
|
21
|
+
<<-'JS'
|
|
22
|
+
//= require hyperstack-loader
|
|
23
|
+
JS
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create_hyperstack_directories
|
|
28
|
+
create_file 'app/hyperstack/components/hyper_component.rb', <<-RUBY
|
|
29
|
+
class HyperComponent
|
|
30
|
+
include Hyperstack::Component
|
|
31
|
+
include Hyperstack::State::Observer
|
|
32
|
+
end
|
|
33
|
+
RUBY
|
|
34
|
+
create_file 'app/hyperstack/operations/.keep', ''
|
|
35
|
+
create_file 'app/hyperstack/stores/.keep', ''
|
|
36
|
+
create_file 'app/hyperstack/models/.keep', ''
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def move_and_update_application_record
|
|
40
|
+
unless File.exists? 'app/hyperstack/models/application_record.rb'
|
|
41
|
+
`mv app/models/application_record.rb app/hyperstack/models/application_record.rb`
|
|
42
|
+
create_file 'app/models/application_record.rb', <<-RUBY
|
|
43
|
+
# app/models/application_record.rb
|
|
44
|
+
# the presence of this file prevents rails migrations from recreating application_record.rb see https://github.com/rails/rails/issues/29407
|
|
45
|
+
|
|
46
|
+
require 'models/application_record.rb'
|
|
47
|
+
RUBY
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def create_policies_directory
|
|
52
|
+
create_file 'app/policies/application_policy.rb', <<-RUBY
|
|
53
|
+
# app/policies/application_policy
|
|
54
|
+
|
|
55
|
+
# Policies regulate access to your public models
|
|
56
|
+
# The following policy will open up full access (but only in development)
|
|
57
|
+
# The policy system is very flexible and powerful. See the documentation
|
|
58
|
+
# for complete details.
|
|
59
|
+
class Hyperstack::ApplicationPolicy
|
|
60
|
+
# Allow any session to connect:
|
|
61
|
+
always_allow_connection
|
|
62
|
+
# Send all attributes from all public models
|
|
63
|
+
regulate_all_broadcasts { |policy| policy.send_all }
|
|
64
|
+
# Allow all changes to public models
|
|
65
|
+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
|
|
66
|
+
# allow remote access to all scopes - i.e. you can count or get a list of ids
|
|
67
|
+
# for any scope or relationship
|
|
68
|
+
ApplicationRecord.regulate_scope :all
|
|
69
|
+
end unless Rails.env.production?
|
|
70
|
+
RUBY
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def add_router
|
|
74
|
+
generate "hyper:router", "App"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def add_webpacker_manifests
|
|
78
|
+
return if skip_webpack?
|
|
79
|
+
create_file 'app/javascript/packs/client_and_server.js', <<-JAVASCRIPT
|
|
80
|
+
//app/javascript/packs/client_and_server.js
|
|
81
|
+
// these packages will be loaded both during prerendering and on the client
|
|
82
|
+
React = require('react'); // react-js library
|
|
83
|
+
History = require('history'); // react-router history library
|
|
84
|
+
ReactRouter = require('react-router'); // react-router js library
|
|
85
|
+
ReactRouterDOM = require('react-router-dom'); // react-router DOM interface
|
|
86
|
+
ReactRailsUJS = require('react_ujs'); // interface to react-rails
|
|
87
|
+
// to add additional NPM packages call run yarn package-name@version
|
|
88
|
+
// then add the require here.
|
|
89
|
+
JAVASCRIPT
|
|
90
|
+
create_file 'app/javascript/packs/client_only.js', <<-JAVASCRIPT
|
|
91
|
+
//app/javascript/packs/client_only.js
|
|
92
|
+
// add any requires for packages that will run client side only
|
|
93
|
+
ReactDOM = require('react-dom'); // react-js client side code
|
|
94
|
+
jQuery = require('jquery');
|
|
95
|
+
// to add additional NPM packages call run yarn package-name@version
|
|
96
|
+
// then add the require here.
|
|
97
|
+
JAVASCRIPT
|
|
98
|
+
append_file 'config/initializers/assets.rb' do
|
|
99
|
+
<<-RUBY
|
|
100
|
+
Rails.application.config.assets.paths << Rails.root.join('public', 'packs').to_s
|
|
101
|
+
RUBY
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def add_webpacks
|
|
106
|
+
return if skip_webpack?
|
|
107
|
+
yarn 'react', '16'
|
|
108
|
+
yarn 'react-dom', '16'
|
|
109
|
+
yarn 'react-router', '4.2'
|
|
110
|
+
yarn 'react-router-dom', '4.2'
|
|
111
|
+
yarn 'history', '4.2'
|
|
112
|
+
yarn 'react_ujs'
|
|
113
|
+
yarn 'jquery'
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def add_framework
|
|
117
|
+
framework = options['add-framework']
|
|
118
|
+
return unless framework
|
|
119
|
+
generate "hyperstack:install_#{framework}", "--no-build"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def build_webpack
|
|
123
|
+
system('bin/webpack')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# all generators should be run before the initializer due to the opal-rails opal-jquery
|
|
127
|
+
# conflict
|
|
128
|
+
|
|
129
|
+
def create_initializer
|
|
130
|
+
create_file 'config/initializers/hyperstack.rb', <<-RUBY
|
|
131
|
+
# config/initializers/hyperstack.rb
|
|
132
|
+
# If you are not using ActionCable, see http://hyperstack.orgs/docs/models/configuring-transport/
|
|
133
|
+
Hyperstack.configuration do |config|
|
|
134
|
+
config.transport = :action_cable # or :pusher or :simpler_poller or :none
|
|
135
|
+
config.prerendering = :off # or :on
|
|
136
|
+
#{" config.import 'jquery', client_only: true # remove this line if you don't need jquery" if skip_webpack?}
|
|
137
|
+
config.import 'hyperstack/component/jquery', client_only: true # remove this line if you don't need jquery
|
|
138
|
+
#{" config.import 'hyperstack/hotloader', client_only: true if Rails.env.development?" unless options['skip-hot-reloader']}
|
|
139
|
+
end
|
|
140
|
+
RUBY
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def inject_engine_to_routes
|
|
144
|
+
# this needs to be the first route, thus it must be the last method executed
|
|
145
|
+
route 'mount Hyperstack::Engine => \'/hyperstack\'' # this route should be first in the routes file so it always matches
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def add_opal_hot_reloader
|
|
149
|
+
return if options['skip-hot-reloader']
|
|
150
|
+
create_file 'Procfile', <<-TEXT
|
|
151
|
+
web: bundle exec rails s -b 0.0.0.0
|
|
152
|
+
hot-loader: bundle exec hyperstack-hotloader -d app/hyperstack
|
|
153
|
+
TEXT
|
|
154
|
+
gem_group :development do
|
|
155
|
+
gem 'foreman'
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def add_gems
|
|
160
|
+
# gem 'hyper-model', Hyperstack::VERSION
|
|
161
|
+
# gem 'hyper-router', Hyperstack::ROUTERVERSION
|
|
162
|
+
# gem 'opal-rails', '~> 0.9.4'
|
|
163
|
+
# gem 'opal-jquery'
|
|
164
|
+
# gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def install
|
|
168
|
+
Bundler.with_clean_env do
|
|
169
|
+
run "bundle install"
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
private
|
|
174
|
+
|
|
175
|
+
def skip_webpack?
|
|
176
|
+
options['skip-webpack'] || !defined?(Webpacker)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
|
|
3
|
+
module Rails
|
|
4
|
+
module Generators
|
|
5
|
+
class Base < Thor::Group
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
def add_to_manifest(manifest, &block)
|
|
10
|
+
if File.exists? "app/javascript/packs/#{manifest}"
|
|
11
|
+
append_file "app/javascript/packs/#{manifest}", &block
|
|
12
|
+
else
|
|
13
|
+
create_file "app/javascript/packs/#{manifest}", &block
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def yarn(package, version = nil)
|
|
18
|
+
return if system("yarn add #{package}#{'@' + version if version}")
|
|
19
|
+
raise Thor::Error.new("yarn failed to install #{package} with version #{version}")
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require_relative 'install_generator_base'
|
|
2
|
+
module Hyperstack
|
|
3
|
+
class InstallMuiGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
desc "Adds the bits you need for the MUI framework"
|
|
6
|
+
|
|
7
|
+
class_option 'no-build', type: :boolean
|
|
8
|
+
|
|
9
|
+
def insure_yarn_loaded
|
|
10
|
+
begin
|
|
11
|
+
yarn_version = `yarn --version`
|
|
12
|
+
raise Errno::ENOENT if yarn_version.blank?
|
|
13
|
+
rescue Errno::ENOENT
|
|
14
|
+
raise Thor::Error.new("please insure the yarn command is available if using webpacker")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_to_manifests
|
|
19
|
+
add_to_manifest('client_and_server.js') { "Mui = require('muicss/react');\n" }
|
|
20
|
+
add_to_manifest('application.scss') { "@import '~muicss/lib/sass/mui'\n" }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_style_sheet_pack_tag
|
|
24
|
+
inject_into_file 'app/views/layouts/application.html.erb', after: /stylesheet_link_tag.*$/ do
|
|
25
|
+
"\n <%= stylesheet_pack_tag 'application' %>\n"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run_yarn
|
|
30
|
+
yarn 'muicss'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def build_webpack
|
|
34
|
+
system('bin/webpack') unless options['no-build']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def add_sample_component
|
|
38
|
+
create_file 'app/hyperstack/components/mui_sampler.rb' do
|
|
39
|
+
<<-RUBY
|
|
40
|
+
class MuiSampler
|
|
41
|
+
include Hyperstack::Component
|
|
42
|
+
include Hyperstack::State::Observer
|
|
43
|
+
render(DIV) do
|
|
44
|
+
Mui::Appbar()
|
|
45
|
+
Mui::Container() do
|
|
46
|
+
Mui::Button(color: :primary) { 'button' }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
RUBY
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'hyperstack-config'
|
|
2
|
+
require 'rails/generators'
|
|
3
|
+
require 'hyper-state'
|
|
4
|
+
require 'hyper-store'
|
|
5
|
+
|
|
6
|
+
# remove these once lap29 is released ...
|
|
7
|
+
Hyperstack.js_import 'react/react-source-browser', client_only: true, defines: ['ReactDOM', 'React']
|
|
8
|
+
Hyperstack.js_import 'react/react-source-server', server_only: true, defines: 'React'
|
|
9
|
+
#Hyperstack.js_import 'hyper-router/react-router-source', defines: ['ReactRouter', 'ReactRouterDOM', 'History']
|
|
10
|
+
Hyperstack.js_import 'react_ujs', defines: 'ReactRailsUJS'
|
|
11
|
+
# remove above once lap29 is released ...
|
|
12
|
+
|
|
13
|
+
Hyperstack.import 'hyper-router'
|
|
14
|
+
Hyperstack.import 'hyper-model'
|
|
15
|
+
Hyperstack.import 'hyper-state'
|
|
16
|
+
|
|
17
|
+
require 'generators/hyperstack/install_generator'
|
|
18
|
+
require 'generators/hyper/component_generator'
|
|
19
|
+
require 'generators/hyper/router_generator'
|
|
20
|
+
begin
|
|
21
|
+
require 'opal-rails'
|
|
22
|
+
require 'hyper-model'
|
|
23
|
+
require 'hyper-router'
|
|
24
|
+
rescue LoadError
|
|
25
|
+
end
|
|
26
|
+
require 'react-rails'
|
|
27
|
+
require 'opal-browser'
|
|
28
|
+
require 'mini_racer'
|
|
29
|
+
require 'hyperstack/version'
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'hyperstack/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'rails-hyperstack'
|
|
8
|
+
spec.version = Hyperstack::VERSION
|
|
9
|
+
spec.summary = 'Hyperstack for Rails with generators'
|
|
10
|
+
spec.description = 'This gem provide a full hyperstack for rails plus generators for Hyperstack elements'
|
|
11
|
+
spec.authors = ['Loic Boutet', 'Adam George', 'Mitch VanDuyn', 'Jan Biedermann']
|
|
12
|
+
spec.email = ['loic@boutet.com', 'jan@kursator.com']
|
|
13
|
+
spec.homepage = 'http://hyperstack.org'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
# spec.metadata = {
|
|
16
|
+
# "homepage_uri" => 'http://hyperstack.org',
|
|
17
|
+
# "source_code_uri" => 'https://github.com/hyperstack
|
|
18
|
+
# }
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(tasks)/}) }
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
|
+
|
|
22
|
+
spec.add_dependency 'hyper-model', Hyperstack::VERSION
|
|
23
|
+
spec.add_dependency 'hyper-router', Hyperstack::ROUTERVERSION
|
|
24
|
+
spec.add_dependency 'hyperstack-config', Hyperstack::VERSION
|
|
25
|
+
spec.add_dependency 'opal-rails', '~> 0.9.4'
|
|
26
|
+
|
|
27
|
+
spec.add_dependency 'opal-browser', '~> 0.2.0'
|
|
28
|
+
spec.add_dependency 'react-rails', '>= 2.4.0', '< 2.5.0'
|
|
29
|
+
spec.add_dependency 'mini_racer', '~> 0.1.15'
|
|
30
|
+
# https://github.com/discourse/mini_racer/issues/92
|
|
31
|
+
spec.add_dependency 'libv8', '~> 6.3.0'
|
|
32
|
+
spec.add_dependency 'rails', '>= 4.0.0'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# spec.add_development_dependency 'sqlite3'
|
|
36
|
+
# #spec.add_development_dependency 'chromedriver-helper'
|
|
37
|
+
# spec.add_development_dependency 'geminabox', '>= 0.13.11'
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
spec.add_development_dependency 'bundler', '~> 1.16.0'
|
|
41
|
+
spec.add_development_dependency 'chromedriver-helper'
|
|
42
|
+
spec.add_development_dependency 'hyper-spec', Hyperstack::VERSION
|
|
43
|
+
spec.add_development_dependency 'pry'
|
|
44
|
+
spec.add_development_dependency 'puma'
|
|
45
|
+
spec.add_development_dependency 'bootsnap'
|
|
46
|
+
#spec.add_development_dependency 'rake', '~> 10.0'
|
|
47
|
+
spec.add_development_dependency 'rspec'
|
|
48
|
+
spec.add_development_dependency 'rubocop', '~> 0.51.0'
|
|
49
|
+
spec.add_development_dependency 'sqlite3'
|
|
50
|
+
spec.add_development_dependency 'sass-rails', '~> 5.0'
|
|
51
|
+
# Use Uglifier as compressor for JavaScript assets
|
|
52
|
+
spec.add_development_dependency 'uglifier', '>= 1.3.0'
|
|
53
|
+
# See https://github.com/rails/execjs#readme for more supported runtimes
|
|
54
|
+
# gem 'mini_racer', platforms: :ruby
|
|
55
|
+
|
|
56
|
+
# Use CoffeeScript for .coffee assets and views
|
|
57
|
+
spec.add_development_dependency 'coffee-rails', '~> 4.2'
|
|
58
|
+
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
|
|
59
|
+
spec.add_development_dependency 'turbolinks', '~> 5'
|
|
60
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
|
61
|
+
spec.add_development_dependency 'jbuilder', '~> 2.5'
|
|
62
|
+
spec.add_development_dependency 'foreman'
|
|
63
|
+
spec.add_development_dependency 'database_cleaner'
|
|
64
|
+
|
|
65
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'rails-hyperstack' do
|
|
4
|
+
it 'builds a working app', js: true do
|
|
5
|
+
visit '/'
|
|
6
|
+
expect(page).to have_content('App')
|
|
7
|
+
end
|
|
8
|
+
it 'installs hyper-model and friends', js: true do
|
|
9
|
+
visit '/'
|
|
10
|
+
expect_promise do
|
|
11
|
+
Hyperstack::Model.load { Sample.count }
|
|
12
|
+
end.to eq(0)
|
|
13
|
+
evaluate_ruby do
|
|
14
|
+
Sample.create(name: 'sample1', description: 'the first sample')
|
|
15
|
+
end
|
|
16
|
+
wait_for_ajax
|
|
17
|
+
expect(Sample.count).to eq(1)
|
|
18
|
+
expect(Sample.first.name).to eq('sample1')
|
|
19
|
+
expect(Sample.first.description).to eq('the first sample')
|
|
20
|
+
expect_evaluate_ruby do
|
|
21
|
+
Sample.count
|
|
22
|
+
end.to eq(1)
|
|
23
|
+
end
|
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
require 'opal-browser'
|
|
3
|
+
require 'database_cleaner'
|
|
4
|
+
|
|
5
|
+
ENV['RAILS_ENV'] ||= 'development'
|
|
6
|
+
require File.expand_path('../test_app/config/environment', __FILE__)
|
|
7
|
+
|
|
8
|
+
require 'rspec/rails'
|
|
9
|
+
require 'hyper-spec'
|
|
10
|
+
require 'rails-hyperstack'
|
|
11
|
+
require 'puma'
|
|
12
|
+
require 'turbolinks'
|
|
13
|
+
|
|
14
|
+
Capybara.server = :puma
|
|
15
|
+
|
|
16
|
+
RSpec.configure do |config|
|
|
17
|
+
config.color = true
|
|
18
|
+
config.formatter = :documentation
|
|
19
|
+
config.before(:all) do
|
|
20
|
+
`rm -rf spec/test_app/tmp/cache/`
|
|
21
|
+
end
|
|
22
|
+
config.before(:each, :js => true) do
|
|
23
|
+
DatabaseCleaner.strategy = :truncation
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
config.after(:each) do |example|
|
|
27
|
+
unless example.exception
|
|
28
|
+
# Clear session data
|
|
29
|
+
Capybara.reset_sessions!
|
|
30
|
+
# Rollback transaction
|
|
31
|
+
DatabaseCleaner.clean
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|