Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit e9b83bf

Browse files
committed
initial commit - sort of works
1 parent e604378 commit e9b83bf

File tree

8 files changed

+224
-0
lines changed

8 files changed

+224
-0
lines changed

hyperloop.gemspec

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'hyperloop/version'
5+
6+
Gem::Specification.new do |s|
7+
s.name = 'hyperloop'
8+
s.version = Hyperloop::VERSION
9+
s.summary = 'Hyperloop stack and generators for Rails'
10+
s.description = 'This gem provide the full hyperloop stack for rails plus generators for Hyperloop elements'
11+
s.authors = ['Loic Boutet', 'Adam George', 'Mitch VanDuyn']
12+
s.email = 'loic@boutet.com'
13+
s.homepage = "http://ruby-hyperloop.io"
14+
s.license = "MIT"
15+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16+
# s.files = ['lib/hyper-rails.rb',
17+
# 'lib/generators/hyperloop/install_generator.rb',
18+
# 'lib/generators/hyperloop/component_generator.rb',
19+
# 'lib/generators/hyperloop/router_generator.rb',
20+
# 'lib/generators/hyperloop/templates/component_template.rb',
21+
# 'lib/generators/hyperloop/templates/router_template.rb']
22+
s.license = 'MIT'
23+
s.require_paths = ["lib"]
24+
25+
s.add_dependency 'hyper-model'
26+
s.add_dependency 'hyper-spec'
27+
s.add_dependency 'opal-rails', '>= 0.8.1'
28+
s.add_dependency 'opal-browser'
29+
s.add_dependency 'react-rails', '~> 1.9.0'
30+
s.add_dependency 'therubyracer'
31+
s.add_dependency 'react-router-rails', '~> 0.13.3'
32+
s.add_dependency 'hyper-router'
33+
s.add_runtime_dependency 'rails', '>= 4.0.0'
34+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'rails/generators'
2+
module Hyper
3+
class Component < Rails::Generators::Base
4+
source_root File.expand_path('../templates', __FILE__)
5+
6+
argument :components, type: :array
7+
def create_component_file
8+
self.components.each do |component|
9+
component_array = component.split('::')
10+
@modules = component_array[0..-2]
11+
@file_name = component_array.last
12+
@indet = 1
13+
template 'component_template.rb',
14+
File.join('app/hyperloop/components',
15+
@modules.map(&:downcase).join('/'),
16+
"#{@file_name.underscore}.rb")
17+
end
18+
end
19+
end
20+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# require 'rails/generators'
2+
# module Hyperloop
3+
# class Router < Rails::Generators::Base
4+
# source_root File.expand_path('../templates', __FILE__)
5+
# argument :components, type: :array
6+
# def create_component_file
7+
# self.components.each do |component|
8+
# component_array = component.split('::')
9+
# @modules = component_array[0..-2]
10+
# @file_name = component_array.last
11+
# @indet = 1
12+
# template 'router_template.rb',
13+
# File.join('app/views/components',
14+
# @modules.map(&:downcase).join('/'),
15+
# "#{@file_name.underscore}.rb")
16+
# end
17+
# end
18+
# end
19+
# end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Components
2+
<%- @modules.each do |module_name| %><%= " "* @indet %>module <%= module_name.camelize %><%- @indet += 1 %>
3+
<%- end %><%=" "* @indet %>class <%= @file_name %> < Hyperloop::Component
4+
5+
<%=" "* @indet %># param :my_param
6+
<%=" "* @indet %># param param_with_default: "default value"
7+
<%=" "* @indet %># param :param_with_default2, default: "default value" # alternative syntax
8+
<%=" "* @indet %># param :param_with_type, type: Hash
9+
<%=" "* @indet %># param :array_of_hashes, type: [Hash]
10+
<%=" "* @indet %># collect_other_params_as :attributes # collects all other params into a hash
11+
12+
<%=" "* @indet %># The following are the most common lifecycle call backs,
13+
<%=" "* @indet %># the following are the most common lifecycle call backs# delete any that you are not using.
14+
<%=" "* @indet %># call backs may also reference an instance method i.e. before_mount :my_method
15+
16+
<%=" "* @indet %>before_mount do
17+
<%=" "* @indet %> # any initialization particularly of state variables goes here.
18+
<%=" "* @indet %> # this will execute on server (prerendering) and client.
19+
<%=" "* @indet %>end
20+
21+
<%=" "* @indet %>after_mount do
22+
<%=" "* @indet %> # any client only post rendering initialization goes here.
23+
<%=" "* @indet %> # i.e. start timers, HTTP requests, and low level jquery operations etc.
24+
<%=" "* @indet %>end
25+
26+
<%=" "* @indet %>before_update do
27+
<%=" "* @indet %> # called whenever a component will be re-rerendered
28+
<%=" "* @indet %>end
29+
30+
<%=" "* @indet %>before_unmount do
31+
<%=" "* @indet %> # cleanup any thing (i.e. timers) before component is destroyed
32+
<%=" "* @indet %>end
33+
34+
<%=" "* @indet %>def render
35+
<%=" "* @indet %> div do
36+
<%=" "* @indet %> "<%= (@modules+[@file_name]).join('::') %>"
37+
<%=" "* @indet %> end
38+
<%=" "* @indet %>end
39+
<%=" "* @indet %>end
40+
<%- @modules.each do %><%- @indet -= 1 %><%=" "* @indet %>end
41+
<%- end %>end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module Components
2+
<%- @modules.each do |module_name| %><%= " "* @indet %>module <%= module_name.camelize %><%- @indet += 1 %>
3+
<%- end %><%=" "* @indet %>class <%= @file_name %>
4+
5+
<%=" "* @indet %>include React::Router
6+
7+
<%=" "* @indet %>routes(path: "/") do # change path to be the base path
8+
<%=" "* @indet %> # you will probably want to update your config/routes.rb file so that it matches all
9+
<%=" "* @indet %> # subroutes: i.e. get '(*subroutes)' => "<%= (@modules.last || 'home').underscore %>#<%= @file_name.underscore %>"
10+
<%=" "* @indet %> # basic route has:
11+
<%=" "* @indet %> # a path
12+
<%=" "* @indet %> # a name - used to reference the route in methods like redirect, and link)
13+
<%=" "* @indet %> # a handler - the component that will be mounted on this route
14+
<%=" "* @indet %> route(path: "subroute1-path", name: :subroute1, handler: Subroute1Component)
15+
<%=" "* @indet %> route(path: "subroute2-path", name: :subroute2, handler: Subroute2Component)
16+
<%=" "* @indet %> # routes can take parameters designated with a colon:
17+
<%=" "* @indet %> route(path: "subroute3-path/:user_id", name: subroute3, handler: Subroute3Component)
18+
<%=" "* @indet %> # the redirect method will transition any incoming matching routes to a new route
19+
<%=" "* @indet %> redirect(from: "/", to: :subroute1)
20+
<%=" "* @indet %> # the not_found method indicates which component to load if no route matches:
21+
<%=" "* @indet %> not_found(handler: NotFound)
22+
<%=" "* @indet %>end
23+
24+
<%=" "* @indet %>router_param :user_id, as: :user do |id|
25+
<%=" "* @indet %> # Translate incoming route params to internal values.
26+
<%=" "* @indet %> # In this case we will refer to the translated user_id as user.
27+
<%=" "* @indet %> # The block param (id) will have the value of the param.
28+
<%=" "* @indet %> # This is useful for looking up ActiveRecord models by ids, etc.
29+
<%=" "* @indet %>end
30+
31+
<%=" "* @indet %>def show # note that the top level router has a show method NOT render
32+
<%=" "* @indet %> div do
33+
<%=" "* @indet %> # content to display on every route
34+
<%=" "* @indet %> # link generates an anchor tag.
35+
<%=" "* @indet %> link(to: :subroute3, params: {user_id: 12}, class: "link-class") { "Click to go to subroute3" }
36+
<%=" "* @indet %> # within an event handler use transition_to to move to a new route
37+
<%=" "* @indet %> # the route_handler method will display the current route, it can be called in the
38+
<%=" "* @indet %> # router, or in some child component.
39+
<%=" "* @indet %> route_handler
40+
<%=" "* @indet %> end
41+
<%=" "* @indet %>end
42+
<%=" "* @indet %>end
43+
<%- @modules.each do %><%- @indet -= 1 %><%=" "* @indet %>end
44+
<%- end %>end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'rails/generators'
2+
module Hyperloop
3+
class InstallGenerator < Rails::Generators::Base
4+
5+
def inject_react_file_js
6+
append_file 'app/assets/javascripts/application.js' do
7+
<<-'JS'
8+
//= require hyperloop-loader
9+
JS
10+
end
11+
end
12+
13+
def inject_engine_to_routes
14+
route 'mount Hyperloop::Engine => \'/hyperloop\''
15+
end
16+
17+
def create_hyperloop_directories
18+
create_file 'app/hyperloop/components/.keep', ''
19+
create_file 'app/hyperloop/operations/.keep', ''
20+
create_file 'app/hyperloop/stores/.keep', ''
21+
create_file 'app/hyperloop/models/.keep', ''
22+
end
23+
24+
def create_policies_directory
25+
create_file 'app/policies/hyperloop_application_policy.rb', <<-RUBY
26+
# app/policies/application_policy
27+
28+
# Policies regulate access to your public models
29+
# The following policy will open up full access (but only in development)
30+
# The policy system is very flexible and powerful. See the documentation
31+
# for complete details.
32+
class Hyperloop::ApplicationPolicy
33+
# Allow any session to connect:
34+
always_allow_connection
35+
# Send all attributes from all public models
36+
regulate_all_broadcasts { |policy| policy.send_all }
37+
# Allow all changes to public models
38+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
39+
end unless Rails.env.production?
40+
RUBY
41+
end
42+
43+
def add_gems
44+
end
45+
end
46+
end

lib/hyperloop.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'hyperloop-config'
2+
require 'rails/generators'
3+
require 'hyper-model'
4+
Hyperloop.import 'react_router', client_only: true
5+
6+
require 'generators/hyperloop/install_generator'
7+
require 'generators/hyper/component_generator'
8+
require 'generators/hyper/router_generator'
9+
require 'opal-rails'
10+
require 'react-rails'
11+
require 'hyper-model'
12+
require 'hyper-spec'
13+
require 'opal-browser'
14+
require 'therubyracer'
15+
require 'hyper-router'
16+
require 'react/router/rails'
17+
require 'hyperloop/version'

lib/hyperloop/version.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Hyperloop
2+
VERSION = '0.5.0'
3+
end

0 commit comments

Comments
 (0)