tao_on_rails 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -11
- data/Rakefile +1 -1
- data/lib/assets/javascripts/tao/page.coffee +1 -1
- data/lib/generators/tao/assets/USAGE +18 -0
- data/lib/generators/tao/assets/assets_generator.rb +8 -0
- data/lib/generators/tao/channel/USAGE +9 -0
- data/lib/generators/tao/channel/channel_generator.rb +17 -0
- data/lib/generators/tao/channel/templates/channel.coffee.erb +20 -0
- data/lib/generators/tao/channel/templates/channel.rb.erb +13 -0
- data/lib/generators/tao/coffee/USAGE +15 -0
- data/lib/generators/tao/coffee/coffee_generator.rb +27 -0
- data/lib/generators/tao/coffee/templates/coffee.erb +14 -0
- data/lib/generators/tao/controller/USAGE +8 -0
- data/lib/generators/tao/controller/controller_generator.rb +20 -0
- data/lib/generators/tao/controller/templates/controller.rb.erb +57 -0
- data/lib/generators/tao/locale/USAGE +11 -0
- data/lib/generators/tao/locale/locale_generator.rb +34 -0
- data/lib/generators/tao/locale/templates/model.yml.erb +7 -0
- data/lib/generators/tao/sass/USAGE +15 -0
- data/lib/generators/tao/sass/sass_generator.rb +27 -0
- data/lib/generators/tao/sass/templates/sass.erb +3 -0
- data/lib/generators/tao/scaffold/USAGE +22 -0
- data/lib/generators/tao/scaffold/scaffold_generator.rb +16 -0
- data/lib/generators/tao/view/USAGE +9 -0
- data/lib/generators/tao/view/templates/create.js.coffee +5 -0
- data/lib/generators/tao/view/templates/destroy.js.coffee +2 -0
- data/lib/generators/tao/view/templates/edit.html.erb +1 -0
- data/lib/generators/tao/view/templates/index.html.erb +1 -0
- data/lib/generators/tao/view/templates/new.html.erb +1 -0
- data/lib/generators/tao/view/templates/show.html.erb +1 -0
- data/lib/generators/tao/view/templates/update.js.coffee +5 -0
- data/lib/generators/tao/view/view_generator.rb +38 -0
- data/lib/tao_on_rails/{rails/engine.rb → engine.rb} +2 -3
- data/lib/tao_on_rails/version.rb +3 -0
- data/lib/tao_on_rails.rb +2 -4
- data/lib/tasks/{tao_icons.rake → icons.rake} +1 -1
- data/lib/templates/app/app_template.rb +60 -0
- data/lib/templates/app/templates/app/assets/javascripts/application.coffee +12 -0
- data/lib/templates/app/templates/app/assets/javascripts/home/index_page.coffee +14 -0
- data/lib/templates/app/templates/app/assets/stylesheets/application.scss +10 -0
- data/lib/templates/app/templates/app/assets/stylesheets/home/index_page.scss +3 -0
- data/lib/templates/app/templates/app/controllers/home_controller.rb +2 -0
- data/lib/templates/app/templates/app/helpers/application_helper.rb +8 -0
- data/lib/templates/app/templates/app/views/home/index.html.erb +1 -0
- data/lib/templates/app/templates/app/views/layouts/application.html.erb +22 -0
- data/lib/templates/plugin/plugin_template.rb +67 -0
- data/lib/templates/plugin/templates/Rakefile +10 -0
- data/lib/templates/plugin/templates/index.html +29 -0
- data/lib/templates/plugin/templates/lib/assets/javascripts/plugin_name.coffee +14 -0
- data/lib/templates/plugin/templates/lib/assets/stylesheets/plugin_name.scss +4 -0
- data/lib/templates/plugin/templates/lib/plugin_name/engine.rb +7 -0
- data/lib/templates/plugin/templates/plugin_name.gemspec +23 -0
- data/lib/templates/plugin/templates/test/javascripts/plugin_name_test.coffee +21 -0
- data/lib/templates/plugin/templates/test/plugin_name_test.rb +13 -0
- data/lib/templates/plugin/templates/test/test_helper.rb +9 -0
- metadata +59 -62
- data/.DS_Store +0 -0
- data/.blade.yml +0 -38
- data/.gitignore +0 -10
- data/.travis.yml +0 -10
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -4
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/dist/tao.css +0 -475
- data/dist/tao.js +0 -31224
- data/lib/tao_on_rails/rails/railtie.rb +0 -9
- data/lib/tao_on_rails/rails/version.rb +0 -5
- data/lib/tao_on_rails/rails.rb +0 -3
- data/tao_on_rails.gemspec +0 -34
- data/vendor/assets/javascripts/.DS_Store +0 -0
- data/vendor/assets/javascripts/polyfills/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c6267c2913b2dde1120969bb3d9aaf31fbd44a
|
4
|
+
data.tar.gz: 348f07e5e6b7ae5bf850e2f1739cbe2c10939045
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b2ca6b983f5edbbaa9485f758226393ad1a0381cf571ba7c822d57f586531a630f6420ff91edaefcbcbfafe642ecec8f15701fef4de36953bb6b1c8fbdb9b06
|
7
|
+
data.tar.gz: 6fea03e197c664e99f21dc59dae336c69851c1b5eb33bb518b6671c440cf57e1dc578f6d0312ef5ef9a23b035433214025dcd3d509c5ccdd662f78667aec01dc
|
data/README.md
CHANGED
@@ -1,26 +1,33 @@
|
|
1
1
|
# Tao on Rails [![Build Status](https://travis-ci.org/mycolorway/tao_on_rails.svg?branch=master)](https://travis-ci.org/mycolorway/tao_on_rails)
|
2
2
|
|
3
|
-
[Ruby on Rails](http://rubyonrails.org/) lacks a recommended way to structure your frontend code for many years. Tao on Rails is the framework to fill the gap which will modularize your page with the new [Custom Elements v1](https://developers.google.com/web/fundamentals/getting-started/primers/customelements) API.
|
3
|
+
[Ruby on Rails](http://rubyonrails.org/) lacks a recommended way to structure your frontend code in large project for many years. Tao on Rails is the framework to fill the gap which will modularize your page with the new [Custom Elements v1](https://developers.google.com/web/fundamentals/getting-started/primers/customelements) API.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Usage
|
6
6
|
|
7
|
-
|
7
|
+
Create new Tao on Rails application with following commands:
|
8
8
|
|
9
|
-
```
|
10
|
-
|
9
|
+
```bash
|
10
|
+
rails new app_name -m https://git.io/vM1lZ
|
11
11
|
```
|
12
12
|
|
13
|
-
|
13
|
+
Several generators are available for you to quickly start your work:
|
14
14
|
|
15
|
-
|
15
|
+
* tao:assets
|
16
|
+
* tao:view
|
17
|
+
* tao:controller
|
18
|
+
* tao:locale
|
19
|
+
* tao:channel
|
20
|
+
* tao:scaffold
|
16
21
|
|
17
|
-
|
22
|
+
It is recommended to use `tao:scaffold` generator as first step of your workflow. See `rails g tao:scaffold --help` for more information.
|
18
23
|
|
19
|
-
|
24
|
+
## Plugin
|
20
25
|
|
21
|
-
|
26
|
+
Start writing plugin for Tao on Rails with following commands:
|
22
27
|
|
23
|
-
|
28
|
+
```bash
|
29
|
+
rails plugin new plugin_name -m https://git.io/vM1lE
|
30
|
+
```
|
24
31
|
|
25
32
|
## Contributing
|
26
33
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
Description:
|
2
|
+
Generate assets files for tao page.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
`rails generate tao:assets employee index`
|
6
|
+
|
7
|
+
Create files:
|
8
|
+
app/assets/javascripts/employees/index_page.coffee
|
9
|
+
app/assets/stylesheets/employees/index_page.scss
|
10
|
+
|
11
|
+
|
12
|
+
`rails generate tao:assets home index --variants=default phone`
|
13
|
+
|
14
|
+
Create files:
|
15
|
+
app/assets/javascripts/default/employees/index_page.coffee
|
16
|
+
app/assets/stylesheets/default/employees/index_page.scss
|
17
|
+
app/assets/javascripts/phone/employees/index_page.coffee
|
18
|
+
app/assets/stylesheets/phone/employees/index_page.scss
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Tao
|
2
|
+
module Generators
|
3
|
+
class ChannelGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :actions, type: :array, default: [], banner: "method method"
|
7
|
+
|
8
|
+
check_class_collision suffix: "Channel"
|
9
|
+
|
10
|
+
def create_channel_files
|
11
|
+
template "channel.coffee.erb", "app/assets/javascripts/channels/#{name.singularize}.coffee"
|
12
|
+
template "channel.rb.erb", "app/channels/#{name.singularize}_channel.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
app.<%= class_name.camelize(:lower) %>Channel = app.cable.subscriptions.create "<%= class_name %>Channel",
|
2
|
+
connected: ->
|
3
|
+
# Called when the subscription is ready for use on the server
|
4
|
+
if app.currentPage
|
5
|
+
currentPage.trigger 'channel-connected', ['<%= class_name.underscore %>']
|
6
|
+
|
7
|
+
disconnected: ->
|
8
|
+
# Called when the subscription has been terminated by the server
|
9
|
+
if app.currentPage
|
10
|
+
currentPage.trigger 'channel-disconnected', ['<%= class_name.underscore %>']
|
11
|
+
|
12
|
+
received: (data) ->
|
13
|
+
# Called when there's incoming data on the websocket for this channel
|
14
|
+
if app.currentPage
|
15
|
+
currentPage.trigger 'channel-received', ['<%= class_name.underscore %>', data]
|
16
|
+
<% actions.each do |action| -%>
|
17
|
+
|
18
|
+
<%= action %>: ->
|
19
|
+
@perform '<%= action %>'
|
20
|
+
<% end -%>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= class_name %>Channel < ApplicationCable::Channel
|
2
|
+
def subscribed
|
3
|
+
# stream_from "some_channel"
|
4
|
+
end
|
5
|
+
|
6
|
+
def unsubscribed
|
7
|
+
# Any cleanup needed when channel is unsubscribed
|
8
|
+
end
|
9
|
+
<% actions.each do |action| -%>
|
10
|
+
def <%= action %>
|
11
|
+
end
|
12
|
+
<% end -%>
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Description:
|
2
|
+
Generate coffee files for tao page.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
`rails generate tao:coffee employee new`
|
6
|
+
|
7
|
+
Create coffee file:
|
8
|
+
app/assets/javascripts/employees/new.coffee
|
9
|
+
|
10
|
+
|
11
|
+
`rails generate tao:coffee employee index --variants=default phone`
|
12
|
+
|
13
|
+
Create coffee files:
|
14
|
+
app/assets/javascripts/default/employees/index.coffee
|
15
|
+
app/assets/javascripts/phone/employees/index.coffee
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Tao
|
2
|
+
module Generators
|
3
|
+
class CoffeeGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :actions, type: :array, default: %w(index new edit show), banner: "new edit"
|
7
|
+
|
8
|
+
class_option :variants, type: :array, default: [], desc: "Generate assets for different variants"
|
9
|
+
|
10
|
+
attr_reader :page_id
|
11
|
+
|
12
|
+
def create_coffee_file
|
13
|
+
actions.each do |action|
|
14
|
+
@page_id = [class_path, file_name, action].flatten.join('-')
|
15
|
+
if (variants = options[:variants]).any?
|
16
|
+
variants.each do |variant|
|
17
|
+
template "coffee.erb", File.join("app/assets/javascripts", variant, name.pluralize, "#{action}_page.coffee")
|
18
|
+
end
|
19
|
+
else
|
20
|
+
template "coffee.erb", File.join('app/assets/javascripts', name.pluralize, "#{action}_page.coffee")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class <%= page_id.underscore.camelize %>Page extends TaoPage
|
2
|
+
|
3
|
+
@tag: "<%= page_id %>-page"
|
4
|
+
|
5
|
+
_init: ->
|
6
|
+
# called when the page connected to dom for the first time
|
7
|
+
|
8
|
+
_connected: ->
|
9
|
+
# called every time the page connected to dom
|
10
|
+
|
11
|
+
_disconnected: ->
|
12
|
+
# called every time the page disconnected from dom
|
13
|
+
|
14
|
+
TaoPage.register <%= page_id.underscore.camelize %>Page
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Tao
|
2
|
+
module Generators
|
3
|
+
|
4
|
+
class ControllerGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :actions, type: :array, default: %w(index new create edit update show destroy), banner: "action action"
|
8
|
+
|
9
|
+
check_class_collision suffix: "Controller"
|
10
|
+
|
11
|
+
attr_reader :resource
|
12
|
+
|
13
|
+
def create_controller_file
|
14
|
+
@resource = file_name.singularize
|
15
|
+
template "controller.rb.erb", File.join('app/controllers', class_path, "#{file_name}_controller.rb")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class <%= class_name %>Controller < ApplicationController
|
2
|
+
<% if "new".in? actions %>
|
3
|
+
def new
|
4
|
+
build_<%= resource %>
|
5
|
+
end
|
6
|
+
<% end -%>
|
7
|
+
<% if "create".in? actions %>
|
8
|
+
def create
|
9
|
+
build_<%= resource %>
|
10
|
+
@<%= resource %>.save
|
11
|
+
end
|
12
|
+
<% end -%>
|
13
|
+
<% if "edit".in? actions %>
|
14
|
+
def edit
|
15
|
+
load_<%= resource %>
|
16
|
+
build_<%= resource %>
|
17
|
+
end
|
18
|
+
<% end -%>
|
19
|
+
<% if "update".in? actions %>
|
20
|
+
def update
|
21
|
+
load_<%= resource %>
|
22
|
+
build_<%= resource %>
|
23
|
+
@<%= resource %>.save
|
24
|
+
end
|
25
|
+
<% end -%>
|
26
|
+
<% if "show".in? actions %>
|
27
|
+
def show
|
28
|
+
load_<%= resource %>
|
29
|
+
end
|
30
|
+
<% end -%>
|
31
|
+
<% if "destroy".in? actions %>
|
32
|
+
def destroy
|
33
|
+
load_<%= resource %>
|
34
|
+
@<%= resource %>.destroy
|
35
|
+
end
|
36
|
+
<% end -%>
|
37
|
+
<% unless actions.empty? %>
|
38
|
+
private
|
39
|
+
<% end -%>
|
40
|
+
<% unless actions == %w(destroy) %>
|
41
|
+
def build_<%= resource %>
|
42
|
+
@<%= resource %> ||= <%= class_name %>.new
|
43
|
+
@<%= resource %>.attributes = <%= resource %>_params
|
44
|
+
end
|
45
|
+
<% end -%>
|
46
|
+
<% if (actions & %w(edit update show destroy)).any? %>
|
47
|
+
def load_<%= resource %>
|
48
|
+
@<%= resource %> = <%= class_name %>.find params[:id]
|
49
|
+
end
|
50
|
+
<% end -%>
|
51
|
+
<% unless actions == %w(destroy) %>
|
52
|
+
def <%= resource %>_params
|
53
|
+
params.fetch(:<%= singular_table_name %>, {}).permit()
|
54
|
+
end
|
55
|
+
<% end -%>
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Description:
|
2
|
+
Generate locale files
|
3
|
+
|
4
|
+
Example:
|
5
|
+
`rails generate tao:locale namespace/resource zh-CN en`
|
6
|
+
|
7
|
+
Create files:
|
8
|
+
config/locales/models/namespace/resource/zh-CN.yml
|
9
|
+
config/locales/models/namespace/resource/en.yml
|
10
|
+
config/locales/views/namespace/resources/zh-CN.yml
|
11
|
+
config/locales/views/namespace/resources/en.yml
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Tao
|
2
|
+
module Generators
|
3
|
+
class LocaleGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :locales, type: :array, default: [I18n.locale], banner: "locale locale"
|
7
|
+
|
8
|
+
class_option :model, type: :boolean, default: true, desc: "Generate locale files for model"
|
9
|
+
class_option :view, type: :boolean, default: true, desc: "Generate locale files for view"
|
10
|
+
|
11
|
+
attr_reader :locale
|
12
|
+
|
13
|
+
def copy_to_model
|
14
|
+
return unless options[:model]
|
15
|
+
locales.each do |locale|
|
16
|
+
@locale = locale
|
17
|
+
template "model.yml.erb", File.join('config/locales/models', name.pluralize, "#{locale}.yml")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_to_view
|
22
|
+
return unless options[:view]
|
23
|
+
file_content = (class_path + [plural_name]).reverse.inject(nil) do |content, path|
|
24
|
+
{ path => content }
|
25
|
+
end
|
26
|
+
locales.each do |locale|
|
27
|
+
@locale = locale
|
28
|
+
create_file File.join('config/locales/views', name.pluralize, "#{locale}.yml"), {locale => file_content}.to_yaml
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<%= locale %>:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
<%= template_namespace = class_path.map(&:pluralize).join('/') %>/<%= template_name = singular_name.singularize %>: <%= template_name.capitalize %>
|
5
|
+
attributes:
|
6
|
+
<%= template_namespace %>/<%= template_name %>:
|
7
|
+
# attributes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Description:
|
2
|
+
Generate sass files for tao page.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
`rails generate tao:sass employee new`
|
6
|
+
|
7
|
+
Create coffee file:
|
8
|
+
app/assets/stylesheets/employees/new.coffee
|
9
|
+
|
10
|
+
|
11
|
+
`rails generate tao:sass employee index --variants=default phone`
|
12
|
+
|
13
|
+
Create coffee files:
|
14
|
+
app/assets/stylesheets/default/employees/index.coffee
|
15
|
+
app/assets/stylesheets/phone/employees/index.coffee
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Tao
|
2
|
+
module Generators
|
3
|
+
class SassGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :actions, type: :array, default: %w(index new edit show), banner: "action action"
|
7
|
+
|
8
|
+
class_option :variants, type: :array, default: [], desc: "Generate assets for different variants"
|
9
|
+
|
10
|
+
attr_reader :page_id
|
11
|
+
|
12
|
+
def create_sass_file
|
13
|
+
actions.each do |action|
|
14
|
+
@page_id = [class_path, file_name, action].flatten.join('-')
|
15
|
+
if (variants = options[:variants]).any?
|
16
|
+
variants.each do |variant|
|
17
|
+
template "sass.erb", File.join("app/assets/stylesheets", variant, name.pluralize, "#{action}_page.scss")
|
18
|
+
end
|
19
|
+
else
|
20
|
+
template "sass.erb", File.join('app/assets/stylesheets', name.pluralize, "#{action}_page.scss")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds all files in the workflow of tao.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
`rails generate tao:scaffold employees/salary index show --channel --locale`
|
6
|
+
|
7
|
+
Create files:
|
8
|
+
app/assets/javascripts/employees/salaries/index_page.coffee
|
9
|
+
app/assets/javascripts/employees/salaries/show_page.coffee
|
10
|
+
app/assets/stylesheets/employees/salaries/index_page.scss
|
11
|
+
app/assets/stylesheets/employees/salaries/show_page.scss
|
12
|
+
|
13
|
+
app/views/employees/salaries/index.html.erb
|
14
|
+
app/views/employees/salaries/show.html.coffee
|
15
|
+
|
16
|
+
app/controllers/employees/salaries_conroller.rb
|
17
|
+
|
18
|
+
app/assets/javascripts/channels/employees/salary.coffee
|
19
|
+
app/channels/employees/salary_channel.rb
|
20
|
+
|
21
|
+
config/locales/models/employees/salaries/en.yml
|
22
|
+
config/locales/views/employees/salaries/en.yml
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Tao
|
2
|
+
module Generators
|
3
|
+
class ScaffoldGenerator < Rails::Generators::NamedBase
|
4
|
+
|
5
|
+
argument :actions, type: :array, default: %w(index new create edit update show destroy), banner: "action action"
|
6
|
+
|
7
|
+
hook_for 'view', in: :tao, type: :boolean, default: true
|
8
|
+
hook_for 'controller', in: :tao, type: :boolean, default: true
|
9
|
+
hook_for 'assets', in: :tao, type: :boolean, default: true
|
10
|
+
|
11
|
+
hook_for 'locale', in: :tao, type: :array do |instance, locale|
|
12
|
+
instance.invoke 'tao:locale', [instance.name] << locale
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= @<%= @resource %>.inspect %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= @<%= @resource.pluralize %>.inspect %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= @<%= @resource %>.inspect %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= @<%= @resource %>.inspect %>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Tao
|
2
|
+
module Generators
|
3
|
+
class ViewGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
argument :actions, type: :array, default: %w(index show new create edit update destroy), banner: "action action"
|
7
|
+
|
8
|
+
class_option :variants, type: :array, default: [], desc: "Generate assets for different variants"
|
9
|
+
|
10
|
+
attr_reader :resource
|
11
|
+
|
12
|
+
def create_view_files
|
13
|
+
@resource = file_name.singularize
|
14
|
+
view_path = Pathname.new(File.join("app/views", name.pluralize))
|
15
|
+
|
16
|
+
actions.each do |action|
|
17
|
+
if (variants = options[:variants]).any?
|
18
|
+
variants.each do |variant|
|
19
|
+
variant = variant == 'default' ? '' : "+#{variant}"
|
20
|
+
if action.in? %w(create update destroy)
|
21
|
+
template "#{action}.js.coffee", view_path.join("#{action}.js#{variant}.coffee")
|
22
|
+
else
|
23
|
+
template "#{action}.html.erb", view_path.join("#{action}.html#{variant}.erb")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
if action.in? %w(create update destroy)
|
28
|
+
template "#{action}.js.coffee", view_path.join("#{action}.js.coffee")
|
29
|
+
else
|
30
|
+
template "#{action}.html.erb", view_path.join("#{action}.html.erb")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/tao_on_rails.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
|
3
|
+
def apply_template!
|
4
|
+
assert_rails_version
|
5
|
+
assert_options
|
6
|
+
add_template_dir_to_source_paths
|
7
|
+
|
8
|
+
gem 'tao_on_rails', github: 'mycolorway/tao_on_rails', branch: 'refactor-structure'
|
9
|
+
|
10
|
+
remove_file 'app/assets/javascripts/cable.js'
|
11
|
+
remove_file 'app/assets/javascripts/application.js'
|
12
|
+
remove_file 'app/assets/stylesheets/application.css'
|
13
|
+
|
14
|
+
template 'app/assets/javascripts/application.coffee'
|
15
|
+
template 'app/assets/stylesheets/application.scss'
|
16
|
+
template 'app/assets/javascripts/home/index_page.coffee'
|
17
|
+
template 'app/assets/stylesheets/home/index_page.scss'
|
18
|
+
|
19
|
+
template 'app/views/layouts/application.html.erb', force: true
|
20
|
+
template 'app/helpers/application_helper.rb', force: true
|
21
|
+
template 'app/views/home/index.html.erb'
|
22
|
+
|
23
|
+
template 'app/controllers/home_controller.rb'
|
24
|
+
route "root to: 'home#index'"
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_rails_version
|
28
|
+
requirement = Gem::Requirement.new('~> 5.0.0')
|
29
|
+
rails_version = Gem::Version.new(Rails::VERSION::STRING)
|
30
|
+
return if requirement.satisfied_by?(rails_version)
|
31
|
+
fail Rails::Generators::Error, 'Rails #{RAILS_REQUIREMENT} is required'
|
32
|
+
end
|
33
|
+
|
34
|
+
def assert_options
|
35
|
+
valid_options = {
|
36
|
+
:skip_gemfile => false,
|
37
|
+
:skip_bundle => false
|
38
|
+
}
|
39
|
+
valid_options.each do |key, expected|
|
40
|
+
next unless options.key?(key)
|
41
|
+
actual = options[key]
|
42
|
+
if actual != expected
|
43
|
+
fail Rails::Generators::Error, "Unsupported option: #{key}=#{actual}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_template_dir_to_source_paths
|
49
|
+
if __FILE__ =~ %r{\Ahttps?://}
|
50
|
+
tmp_dir = Dir.mktmpdir('_tao_template')
|
51
|
+
at_exit { remove_dir tmp_dir }
|
52
|
+
repo_url = 'https://github.com/mycolorway/tao_on_rails.git'
|
53
|
+
git :clone => "--quiet --depth 1 #{repo_url} #{tmp_dir}".shellescape
|
54
|
+
source_paths.unshift File.expand_path('lib/templates/app/templates', tmp_dir)
|
55
|
+
else
|
56
|
+
source_paths.unshift(File.expand_path('../templates', __FILE__))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
apply_template!
|