Skip to content

Commit 1d7b2cb

Browse files
install template for hello world app
1 parent 28dd642 commit 1d7b2cb

2 files changed

Lines changed: 137 additions & 0 deletions

File tree

install/rails-webpacker.rb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Hyperstack 1.0 ALPHA Rails Template
2+
3+
# ----------------------------------- Commit so we have good history of these changes
4+
5+
git :init
6+
git add: "."
7+
git commit: "-m 'Initial commit: Rails base'"
8+
9+
# ----------------------------------- Add the gems
10+
11+
gem 'webpacker'
12+
gem 'opal-sprockets', '~> 0.4.2.0.11.0.3.1' # to ensure we have the latest
13+
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
14+
gem 'hyperloop', git: 'https://github.com/ruby-hyperloop/hyperloop', branch: 'edge'
15+
gem 'hyper-react', git: 'https://github.com/ruby-hyperloop/hyper-react', branch: 'edge'
16+
gem 'hyper-component', git: 'https://github.com/ruby-hyperloop/hyper-component', branch: 'edge'
17+
gem 'hyper-router', git: 'https://github.com/ruby-hyperloop/hyper-router', branch: 'edge'
18+
gem 'hyper-store', git: 'https://github.com/ruby-hyperloop/hyper-store', branch: 'edge'
19+
gem 'hyperloop-config', git: 'https://github.com/ruby-hyperloop/hyperloop-config', branch: 'edge'
20+
gem 'opal_hot_reloader', git: 'https://github.com/fkchang/opal-hot-reloader.git'
21+
22+
gem_group :development do
23+
gem 'foreman'
24+
end
25+
26+
# ----------------------------------- Create the folders
27+
28+
run 'mkdir app/hyperloop'
29+
run 'mkdir app/hyperloop/components'
30+
run 'mkdir app/hyperloop/stores'
31+
run 'mkdir app/hyperloop/models'
32+
run 'mkdir app/hyperloop/operations'
33+
34+
# ----------------------------------- Add .keep files
35+
36+
run 'touch app/hyperloop/components/.keep'
37+
run 'touch app/hyperloop/stores/.keep'
38+
run 'touch app/hyperloop/models/.keep'
39+
run 'touch app/hyperloop/operations/.keep'
40+
41+
# ----------------------------------- Create the Hyperloop config
42+
43+
file 'config/initializers/hyperloop.rb', <<-CODE
44+
Hyperloop.configuration do |config|
45+
# config.transport = :action_cable
46+
config.import 'reactrb/auto-import'
47+
config.import 'opal_hot_reloader'
48+
config.cancel_import 'react/react-source-browser' # bring your own React and ReactRouter via Yarn/Webpacker
49+
end
50+
CODE
51+
52+
# ----------------------------------- Add NPM modules
53+
54+
run 'yarn add react'
55+
run 'yarn add react-dom'
56+
run 'yarn add react-router'
57+
58+
# ----------------------------------- Create thyperstack.js
59+
60+
file 'app/javascript/packs/hyperstack.js', <<-CODE
61+
// Import all the modules
62+
import React from 'react';
63+
import ReactDOM from 'react-dom';
64+
65+
// for opal/hyperloop modules to find React and others they must explicitly be saved
66+
// to the global space, otherwise webpack will encapsulate them locally here
67+
global.React = React;
68+
global.ReactDOM = ReactDOM;
69+
CODE
70+
71+
# ----------------------------------- View template
72+
73+
inject_into_file 'app/views/layouts/application.html.erb', before: %r{<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>} do
74+
<<-CODE
75+
<%= javascript_pack_tag 'hyperstack' %>
76+
CODE
77+
end
78+
79+
# ----------------------------------- application.js
80+
81+
inject_into_file 'app/assets/javascripts/application.js', before: %r{//= require_tree .} do
82+
<<-CODE
83+
//= require jquery
84+
//= require jquery_ujs
85+
//= require hyperloop-loader
86+
CODE
87+
end
88+
89+
# ----------------------------------- Procfile
90+
91+
file 'Procfile', <<-CODE
92+
web: bundle exec puma
93+
hot: opal-hot-reloader -p 25222 -d app/hyperloop/
94+
CODE
95+
96+
# ----------------------------------- OpalHotReloader client
97+
98+
file 'app/hyperloop/components/hot_loader.rb', <<-CODE
99+
require 'opal_hot_reloader'
100+
OpalHotReloader.listen(25222, false)
101+
CODE
102+
103+
# ----------------------------------- Hello World
104+
105+
route "root 'hyperloop#HelloWorld'"
106+
107+
file 'app/hyperloop/components/hello_world.rb', <<-CODE
108+
class HelloWorld < Hyperloop::Component
109+
render do
110+
H1 { "Hello world from Hyperstack!" }
111+
end
112+
end
113+
CODE
114+
115+
# ----------------------------------- Commit Hyperloop setup
116+
117+
after_bundle do
118+
run 'bundle exec rails webpacker:install'
119+
git add: "."
120+
git commit: "-m 'Hyperstack config complete'"
121+
end

install/readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Hyperstack Rails Template
2+
3+
This template will create a new Rails app with Webpacker and Hyperstack 1.0 ALPHA configured.
4+
5+
## Usage
6+
7+
+ `rails new MyApp -m https://rawgit.com/hyperstack-org/hyperstack/edge/ruby/install/rails-webpacker.rb`
8+
9+
## Start the Rails app
10+
11+
+ `foreman start` to start Rails and OpalHotReloader
12+
+ Navigate to `http://localhost:5000/`
13+
14+
## Pre-Requisites
15+
16+
+ Yarn must be installed (https://yarnpkg.com/en/docs/install#mac-stable)

0 commit comments

Comments
 (0)