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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -11
  3. data/Rakefile +1 -1
  4. data/lib/assets/javascripts/tao/page.coffee +1 -1
  5. data/lib/generators/tao/assets/USAGE +18 -0
  6. data/lib/generators/tao/assets/assets_generator.rb +8 -0
  7. data/lib/generators/tao/channel/USAGE +9 -0
  8. data/lib/generators/tao/channel/channel_generator.rb +17 -0
  9. data/lib/generators/tao/channel/templates/channel.coffee.erb +20 -0
  10. data/lib/generators/tao/channel/templates/channel.rb.erb +13 -0
  11. data/lib/generators/tao/coffee/USAGE +15 -0
  12. data/lib/generators/tao/coffee/coffee_generator.rb +27 -0
  13. data/lib/generators/tao/coffee/templates/coffee.erb +14 -0
  14. data/lib/generators/tao/controller/USAGE +8 -0
  15. data/lib/generators/tao/controller/controller_generator.rb +20 -0
  16. data/lib/generators/tao/controller/templates/controller.rb.erb +57 -0
  17. data/lib/generators/tao/locale/USAGE +11 -0
  18. data/lib/generators/tao/locale/locale_generator.rb +34 -0
  19. data/lib/generators/tao/locale/templates/model.yml.erb +7 -0
  20. data/lib/generators/tao/sass/USAGE +15 -0
  21. data/lib/generators/tao/sass/sass_generator.rb +27 -0
  22. data/lib/generators/tao/sass/templates/sass.erb +3 -0
  23. data/lib/generators/tao/scaffold/USAGE +22 -0
  24. data/lib/generators/tao/scaffold/scaffold_generator.rb +16 -0
  25. data/lib/generators/tao/view/USAGE +9 -0
  26. data/lib/generators/tao/view/templates/create.js.coffee +5 -0
  27. data/lib/generators/tao/view/templates/destroy.js.coffee +2 -0
  28. data/lib/generators/tao/view/templates/edit.html.erb +1 -0
  29. data/lib/generators/tao/view/templates/index.html.erb +1 -0
  30. data/lib/generators/tao/view/templates/new.html.erb +1 -0
  31. data/lib/generators/tao/view/templates/show.html.erb +1 -0
  32. data/lib/generators/tao/view/templates/update.js.coffee +5 -0
  33. data/lib/generators/tao/view/view_generator.rb +38 -0
  34. data/lib/tao_on_rails/{rails/engine.rb → engine.rb} +2 -3
  35. data/lib/tao_on_rails/version.rb +3 -0
  36. data/lib/tao_on_rails.rb +2 -4
  37. data/lib/tasks/{tao_icons.rake → icons.rake} +1 -1
  38. data/lib/templates/app/app_template.rb +60 -0
  39. data/lib/templates/app/templates/app/assets/javascripts/application.coffee +12 -0
  40. data/lib/templates/app/templates/app/assets/javascripts/home/index_page.coffee +14 -0
  41. data/lib/templates/app/templates/app/assets/stylesheets/application.scss +10 -0
  42. data/lib/templates/app/templates/app/assets/stylesheets/home/index_page.scss +3 -0
  43. data/lib/templates/app/templates/app/controllers/home_controller.rb +2 -0
  44. data/lib/templates/app/templates/app/helpers/application_helper.rb +8 -0
  45. data/lib/templates/app/templates/app/views/home/index.html.erb +1 -0
  46. data/lib/templates/app/templates/app/views/layouts/application.html.erb +22 -0
  47. data/lib/templates/plugin/plugin_template.rb +67 -0
  48. data/lib/templates/plugin/templates/Rakefile +10 -0
  49. data/lib/templates/plugin/templates/index.html +29 -0
  50. data/lib/templates/plugin/templates/lib/assets/javascripts/plugin_name.coffee +14 -0
  51. data/lib/templates/plugin/templates/lib/assets/stylesheets/plugin_name.scss +4 -0
  52. data/lib/templates/plugin/templates/lib/plugin_name/engine.rb +7 -0
  53. data/lib/templates/plugin/templates/plugin_name.gemspec +23 -0
  54. data/lib/templates/plugin/templates/test/javascripts/plugin_name_test.coffee +21 -0
  55. data/lib/templates/plugin/templates/test/plugin_name_test.rb +13 -0
  56. data/lib/templates/plugin/templates/test/test_helper.rb +9 -0
  57. metadata +59 -62
  58. data/.DS_Store +0 -0
  59. data/.blade.yml +0 -38
  60. data/.gitignore +0 -10
  61. data/.travis.yml +0 -10
  62. data/CODE_OF_CONDUCT.md +0 -74
  63. data/Gemfile +0 -4
  64. data/bin/console +0 -14
  65. data/bin/setup +0 -8
  66. data/dist/tao.css +0 -475
  67. data/dist/tao.js +0 -31224
  68. data/lib/tao_on_rails/rails/railtie.rb +0 -9
  69. data/lib/tao_on_rails/rails/version.rb +0 -5
  70. data/lib/tao_on_rails/rails.rb +0 -3
  71. data/tao_on_rails.gemspec +0 -34
  72. data/vendor/assets/javascripts/.DS_Store +0 -0
  73. data/vendor/assets/javascripts/polyfills/.DS_Store +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18cf70d94e5c971dd3bcf9b0525b324767d55ca7
4
- data.tar.gz: 5ef69465b21078177c69d852bcf0048fdaf8bf3e
3
+ metadata.gz: f3c6267c2913b2dde1120969bb3d9aaf31fbd44a
4
+ data.tar.gz: 348f07e5e6b7ae5bf850e2f1739cbe2c10939045
5
5
  SHA512:
6
- metadata.gz: 16683209053ac132c3d22382a82a511aa63c43193e00631206259ee5b8ce7e4744d8e40f2798fa072c960490c77d2715bd813e10d7e6bdd9b660e22c4d7dd926
7
- data.tar.gz: 1139cd527ef3638a08fe967ac1a67799d99aa21d945d7b40b6600214d5720e325fe0888a9950991b0d8f18e5b83a0a2059fc8e60f156715c25287ac0f2ec2e52
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
- ## Installation
5
+ ## Usage
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Create new Tao on Rails application with following commands:
8
8
 
9
- ```ruby
10
- gem 'tao_on_rails'
9
+ ```bash
10
+ rails new app_name -m https://git.io/vM1lZ
11
11
  ```
12
12
 
13
- And then execute:
13
+ Several generators are available for you to quickly start your work:
14
14
 
15
- $ bundle
15
+ * tao:assets
16
+ * tao:view
17
+ * tao:controller
18
+ * tao:locale
19
+ * tao:channel
20
+ * tao:scaffold
16
21
 
17
- Or install it yourself as:
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
- $ gem install tao_on_rails
24
+ ## Plugin
20
25
 
21
- ## Usage
26
+ Start writing plugin for Tao on Rails with following commands:
22
27
 
23
- TODO: Write usage instructions here.
28
+ ```bash
29
+ rails plugin new plugin_name -m https://git.io/vM1lE
30
+ ```
24
31
 
25
32
  ## Contributing
26
33
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.pattern = 'test/**/*_test.rb'
8
8
  end
9
9
 
10
10
  task :default => :test
@@ -2,7 +2,7 @@
2
2
 
3
3
  class TaoPage extends TaoComponent
4
4
 
5
- @attribute 'layout'
5
+ @attribute 'layout', default: 'default'
6
6
 
7
7
  beforeCache: ->
8
8
  @jp.find('[tao-id]').each (i, el) =>
@@ -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,8 @@
1
+ module Tao
2
+ module Generators
3
+ class AssetsGenerator < ::Rails::Generators::NamedBase
4
+ hook_for "coffee", in: :tao, type: :boolean, default: true
5
+ hook_for "sass", in: :tao, type: :boolean, default: true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generate channel files for action cable.
3
+
4
+ Example:
5
+ `rails generate tao:channel chat speak`
6
+
7
+ Create files:
8
+ app/assets/javascripts/channels/chat.coffee
9
+ app/channels/chat_channel.rb
@@ -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,8 @@
1
+ Description:
2
+ Generate controller files
3
+
4
+ Example:
5
+ `rails generate tao:controller home index`
6
+
7
+ Create file:
8
+ app/controllers/home_controller.rb
@@ -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,3 @@
1
+ <%= page_id.dasherize %>-page {
2
+
3
+ }
@@ -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,9 @@
1
+ Description:
2
+ Generate view files for tao page
3
+
4
+ Example:
5
+ rails generate tao:view options/grant new create
6
+
7
+ This will create:
8
+ app/views/options/grants/new.html.erb
9
+ app/views/options/grants/create.js.coffee
@@ -0,0 +1,5 @@
1
+ <%% if @<%= @resource %>.errors.any? %>
2
+ # handle errors
3
+ <%% else %>
4
+ # perform create actions
5
+ <%% end %>
@@ -0,0 +1,2 @@
1
+ $("#<%%= dom_id(@<%= @resource %>) %>").fadeOut ->
2
+ $(this).remove()
@@ -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,5 @@
1
+ <%% if @<%= @resource %>.errors.any? %>
2
+ # handle errors
3
+ <%% else %>
4
+ # perform update actions
5
+ <%% end %>
@@ -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
@@ -3,8 +3,7 @@ require 'jquery-rails'
3
3
  require 'lodash-rails'
4
4
 
5
5
  module TaoOnRails
6
- module Rails
7
- class Engine < ::Rails::Engine
8
- end
6
+ class Engine < Rails::Engine
7
+
9
8
  end
10
9
  end
@@ -0,0 +1,3 @@
1
+ module TaoOnRails
2
+ VERSION = "0.6.2"
3
+ end
data/lib/tao_on_rails.rb CHANGED
@@ -1,7 +1,5 @@
1
- require "tao_on_rails/rails"
1
+ require 'tao_on_rails/version'
2
+ require 'tao_on_rails/engine'
2
3
 
3
4
  module TaoOnRails
4
- def self.root
5
- File.dirname __dir__
6
- end
7
5
  end
@@ -1,7 +1,7 @@
1
1
  namespace :tao do
2
2
 
3
3
  desc 'generate svg icons.'
4
- task :generate_icons => :environment do
4
+ task :icons => :environment do
5
5
  dir_name = "#{Rails.root}/vendor/assets/javascripts/tao"
6
6
  Dir.mkdir(dir_name) unless File.exists?(dir_name)
7
7
 
@@ -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!