fae-rails 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/app/assets/javascripts/fae/_deploy.js +198 -0
  4. data/app/assets/javascripts/fae/_modals.js +94 -0
  5. data/app/assets/javascripts/fae/application.js +2 -0
  6. data/app/assets/javascripts/fae/form/_ajax.js +4 -2
  7. data/app/assets/javascripts/fae/form/_filtering.js +34 -0
  8. data/app/assets/javascripts/fae/form/_form.js +1 -0
  9. data/app/assets/javascripts/fae/form/_form_manager.js +295 -0
  10. data/app/assets/javascripts/fae/form/_slugger.js.erb +2 -2
  11. data/app/assets/javascripts/fae/form/inputs/_select.js +5 -2
  12. data/app/assets/stylesheets/fae/base.scss +5 -2
  13. data/app/assets/stylesheets/fae/globals/imports/_variables.scss +1 -0
  14. data/app/assets/stylesheets/fae/globals/layout/_base.scss +7 -2
  15. data/app/assets/stylesheets/fae/globals/layout/_content-header.scss +8 -2
  16. data/app/assets/stylesheets/fae/globals/navigation/_header.scss +2 -2
  17. data/app/assets/stylesheets/fae/globals/navigation/_multi-col-subnav.scss +50 -0
  18. data/app/assets/stylesheets/fae/modules/_buttons.scss +11 -0
  19. data/app/assets/stylesheets/fae/modules/_deploy.scss +25 -0
  20. data/app/assets/stylesheets/fae/modules/_modal.scss +25 -0
  21. data/app/assets/stylesheets/fae/modules/_toggles.scss +39 -23
  22. data/app/assets/stylesheets/fae/modules/forms/_asset-actions.scss +1 -1
  23. data/app/assets/stylesheets/fae/modules/forms/_base.scss +1 -1
  24. data/app/assets/stylesheets/fae/modules/forms/_checkbox.scss +1 -1
  25. data/app/assets/stylesheets/fae/modules/forms/_date.scss +16 -0
  26. data/app/assets/stylesheets/fae/modules/forms/_form-manager.scss +82 -0
  27. data/app/assets/stylesheets/fae/modules/forms/_radio.scss +1 -1
  28. data/app/assets/stylesheets/fae/modules/forms/_select.scss +7 -6
  29. data/app/assets/stylesheets/fae/modules/forms/_simple-mde.scss +1 -1
  30. data/app/assets/stylesheets/fae/modules/forms/_textarea.scss +1 -1
  31. data/app/assets/stylesheets/fae/modules/tables/_filters.scss +4 -0
  32. data/app/assets/stylesheets/fae/pages/_login.scss +4 -0
  33. data/app/controllers/fae/application_controller.rb +7 -0
  34. data/app/controllers/fae/base_controller.rb +5 -1
  35. data/app/controllers/fae/deploy_controller.rb +24 -0
  36. data/app/controllers/fae/deploy_hooks_controller.rb +71 -0
  37. data/app/controllers/fae/form_managers_controller.rb +19 -0
  38. data/app/controllers/fae/options_controller.rb +1 -0
  39. data/app/controllers/fae/static_pages_controller.rb +6 -1
  40. data/app/controllers/fae/users_controller.rb +11 -1
  41. data/app/controllers/fae/utilities_controller.rb +18 -6
  42. data/app/helpers/fae/application_helper.rb +26 -1
  43. data/app/helpers/fae/form_helper.rb +26 -2
  44. data/app/helpers/fae/view_helper.rb +22 -9
  45. data/app/models/concerns/fae/base_model_concern.rb +9 -0
  46. data/app/models/fae/change.rb +19 -6
  47. data/app/models/fae/deploy_hook.rb +12 -0
  48. data/app/models/fae/form_manager.rb +24 -0
  49. data/app/models/fae/user.rb +2 -2
  50. data/app/services/fae/netlify_api.rb +197 -0
  51. data/app/views/devise/unlocks/new.html.slim +5 -9
  52. data/app/views/fae/application/_content_form.html.slim +16 -11
  53. data/app/views/fae/application/_file_uploader.html.slim +7 -2
  54. data/app/views/fae/application/_global_search_results.html.slim +1 -1
  55. data/app/views/fae/application/_header.slim +4 -1
  56. data/app/views/fae/application/_mobilenav.slim +3 -0
  57. data/app/views/fae/deploy/index.html.slim +40 -0
  58. data/app/views/fae/deploy_hooks/_form.html.slim +18 -0
  59. data/app/views/fae/deploy_hooks/_table.html.slim +28 -0
  60. data/app/views/fae/deploy_hooks/edit.html.slim +3 -0
  61. data/app/views/fae/deploy_hooks/new.html.slim +3 -0
  62. data/app/views/fae/images/_image_uploader.html.slim +12 -3
  63. data/app/views/fae/options/_form.html.slim +4 -1
  64. data/app/views/fae/pages/activity_log.html.slim +7 -3
  65. data/app/views/fae/pages/home.html.slim +3 -4
  66. data/app/views/fae/shared/_form_header.html.slim +16 -12
  67. data/app/views/fae/shared/_nested_table.html.slim +4 -2
  68. data/app/views/fae/shared/_recent_changes.html.slim +1 -1
  69. data/app/views/fae/shared/_shared_nested_table.html.slim +4 -1
  70. data/app/views/layouts/fae/application.html.slim +1 -0
  71. data/config/deploy.rb +3 -1
  72. data/config/initializers/devise.rb +6 -6
  73. data/config/locales/fae.en.yml +39 -3
  74. data/config/locales/fae.zh-CN.yml +2 -2
  75. data/config/routes.rb +9 -1
  76. data/db/migrate/20140809222030_add_user_table.rb +1 -1
  77. data/db/migrate/20190925153222_create_fae_form_managers.rb +11 -0
  78. data/db/migrate/20220118192729_create_fae_publish_hooks.rb +10 -0
  79. data/db/migrate/20220128133730_rename_publish_hooks.rb +5 -0
  80. data/db/migrate/20220202153607_add_position_to_deploy_hooks.rb +6 -0
  81. data/lib/fae/options.rb +4 -2
  82. data/lib/fae/version.rb +1 -1
  83. data/lib/generators/fae/base_generator.rb +11 -1
  84. data/lib/generators/fae/nested_scaffold_generator.rb +13 -0
  85. data/lib/generators/fae/templates/assets/fae.js +1 -1
  86. data/lib/generators/fae/templates/controllers/nested_scaffold_controller.rb +14 -0
  87. data/lib/generators/fae/templates/initializers/fae.rb +16 -1
  88. data/lib/generators/fae/templates/views/_form.html.slim +10 -1
  89. data/lib/generators/fae/templates/views/_form_index_nested.html.slim +15 -1
  90. data/lib/generators/fae/templates/views/_form_nested.html.slim +19 -2
  91. data/lib/generators/fae/templates/views/static_page_form.html.slim +13 -1
  92. metadata +28 -8
@@ -1,16 +1,17 @@
1
1
  ruby:
2
2
  require_locals ['header'], local_assigns
3
- save_button_text ||= t('fae.form.save')
4
- cancel_button_text ||= t('fae.form.cancel')
5
- cloneable ||= false
6
- clone_button_text ||= t('fae.form.clone')
7
- subnav ||= []
8
- header_as_string = header.is_a?(String) ? header : header.class.name.split('::').last
9
- header_as_string = header_as_string.singularize
10
- title ||= "#{params[:action]} #{header_as_string}".titleize
11
- breadcrumb = !local_assigns[:breadcrumbs].eql?(false)
12
- languages ||= false
13
- show_flash_messages = !local_assigns[:show_flash_messages].eql?(false)
3
+ save_button_text ||= t('fae.form.save')
4
+ cancel_button_text ||= t('fae.form.cancel')
5
+ cloneable ||= false
6
+ clone_button_text ||= t('fae.form.clone')
7
+ launch_manager_text ||= t('fae.form.launch_form_manager')
8
+ subnav ||= []
9
+ header_as_string = header.is_a?(String) ? header : header.class.name.split('::').last
10
+ header_as_string = header_as_string.singularize
11
+ title ||= "#{params[:action]} #{header_as_string}".titleize
12
+ breadcrumb = !local_assigns[:breadcrumbs].eql?(false)
13
+ languages ||= false
14
+ show_flash_messages = !local_assigns[:show_flash_messages].eql?(false)
14
15
 
15
16
  header.content-header.js-content-header
16
17
  - if breadcrumb
@@ -25,9 +26,12 @@ header.content-header.js-content-header
25
26
  .content-header-select
26
27
  = select_tag 'fae-languages', options_for_select(Fae.languages.map(&:reverse), selected), id: 'js-language', class: 'small_pulldown', prompt: 'All Languages'
27
28
 
29
+ - if Fae.use_form_manager
30
+ a.button.js-launch-form-manager href='#' = launch_manager_text
31
+
28
32
  a.button#js-header-cancel href=@index_path = cancel_button_text
29
33
  - if cloneable.present? && params[:id].present?
30
- a.button data-method="post" href="#{@index_path}?from_existing=#{params[:id]}" = clone_button_text
34
+ a.button#js-header-clone data-method="post" href="#{@index_path}?from_existing=#{params[:id]}" = clone_button_text
31
35
  input name="commit" type="submit" value=save_button_text
32
36
 
33
37
  - if subnav.present?
@@ -11,6 +11,7 @@ ruby:
11
11
  assoc_name ||= assoc.to_s # 'restaurant_bars'
12
12
  title ||= assoc_name.titleize # 'Restaurant Bars'
13
13
  add_button_text ||= t('fae.common.add', title: title.singularize)
14
+ hide_add_button ||= false
14
15
  ordered ||= false
15
16
  has_thumb ||= false
16
17
  edit_column ||= false
@@ -33,7 +34,7 @@ ruby:
33
34
  new_path += "item_id=#{parent_item.id}&=item_class=#{parent_item.class.to_s}"
34
35
  end
35
36
 
36
- options_for_table = { index: index, assoc: assoc, assoc_name: assoc_name, title: title, add_button_text: add_button_text, ordered: ordered, has_thumb: has_thumb, edit_column: edit_column, cols: cols, assoc_name_singular: assoc_name_singular, new_path: new_path, edit_path: edit_path }
37
+ options_for_table = { index: index, assoc: assoc, assoc_name: assoc_name, title: title, add_button_text: add_button_text, hide_add_button: hide_add_button, ordered: ordered, has_thumb: has_thumb, edit_column: edit_column, cols: cols, assoc_name_singular: assoc_name_singular, new_path: new_path, edit_path: edit_path }
37
38
  options_for_table[:parent_item] = parent_item unless index
38
39
 
39
40
  section.addedit-form.js-addedit-form class="#{'content' if index}"
@@ -41,7 +42,8 @@ section.addedit-form.js-addedit-form class="#{'content' if index}"
41
42
  == render 'fae/shared/shared_nested_table', options_for_table
42
43
 
43
44
  - else
44
- a.js-add-link.table-add-link.button.-small href=new_path = add_button_text
45
+ - unless hide_add_button
46
+ a.js-add-link.table-add-link.button.-small href=new_path = add_button_text
45
47
  h2 = title
46
48
  - if helper_text.present?
47
49
  h6.table-helper-text = helper_text
@@ -8,7 +8,7 @@
8
8
  th = t('fae.changes.user')
9
9
  th = t('fae.changes.type')
10
10
  th = t('fae.changes.attrs')
11
- th.-action-wide t('fea.changes.modified')
11
+ th.-action-wide = t('fea.changes.modified')
12
12
  tbody
13
13
  - if @item.try(:tracked_changes).present?
14
14
  - @item.tracked_changes.each do |change|
@@ -37,10 +37,13 @@ table class=table_class
37
37
  i.icon-edit
38
38
  td = fae_delete_button item, "/#{fae_path}/#{assoc_name}/#{item.id.to_s}", class: 'js-tooltip table-action js-delete-link', remote: true
39
39
 
40
- - else
40
+ - elsif !hide_add_button
41
41
  tr
42
42
  - td_link = link_to 'add some', new_path, class: 'js-add-link'
43
43
 
44
44
  td colspan=colspan.to_s No #{title} yet, #{td_link}.
45
+ - else
46
+ tr
47
+ td colspan=colspan.to_s No #{title} yet.
45
48
 
46
49
  .js-addedit-form-wrapper
@@ -12,6 +12,7 @@ html
12
12
  body class=body_class
13
13
  == render 'mobilenav'
14
14
  == render 'header'
15
+ .js-form-manager-container
15
16
  section.main-content#js-main-content
16
17
  == render 'sidenav'
17
18
 
data/config/deploy.rb CHANGED
@@ -38,7 +38,8 @@ namespace :deploy do
38
38
  desc 'Symlink secrets.yml'
39
39
  task :symlink_secrets do
40
40
  on roles(:app) do
41
- execute "ln -s #{shared_path}/secrets.yml #{release_path}/config/secrets.yml"
41
+ execute "rm #{release_path}/spec/dummy/config/secrets.yml"
42
+ execute "ln -s #{shared_path}/secrets.yml #{release_path}/spec/dummy/config/secrets.yml"
42
43
  end
43
44
  end
44
45
 
@@ -68,6 +69,7 @@ namespace :deploy do
68
69
  end
69
70
  end
70
71
 
72
+ after 'deploy:updating', 'deploy:symlink_secrets'
71
73
  after :finishing, 'deploy:cleanup'
72
74
 
73
75
  end
@@ -156,27 +156,27 @@ Devise.setup do |config|
156
156
  # Defines which strategy will be used to lock an account.
157
157
  # :failed_attempts = Locks an account after a number of failed attempts to sign in.
158
158
  # :none = No lock strategy. You should handle locking by yourself.
159
- # config.lock_strategy = :failed_attempts
159
+ config.lock_strategy = :failed_attempts
160
160
 
161
161
  # Defines which key will be used when locking and unlocking an account
162
- # config.unlock_keys = [ :email ]
162
+ config.unlock_keys = [ :email ]
163
163
 
164
164
  # Defines which strategy will be used to unlock an account.
165
165
  # :email = Sends an unlock link to the user email
166
166
  # :time = Re-enables login after a certain amount of time (see :unlock_in below)
167
167
  # :both = Enables both strategies
168
168
  # :none = No unlock strategy. You should handle unlocking by yourself.
169
- # config.unlock_strategy = :both
169
+ config.unlock_strategy = :both
170
170
 
171
171
  # Number of authentication tries before locking an account if lock_strategy
172
172
  # is failed attempts.
173
- # config.maximum_attempts = 20
173
+ config.maximum_attempts = 5
174
174
 
175
175
  # Time interval to unlock the account if :time is enabled as unlock_strategy.
176
- # config.unlock_in = 1.hour
176
+ config.unlock_in = 1.hour
177
177
 
178
178
  # Warn on the last attempt before the account is locked.
179
- # config.last_attempt_warning = false
179
+ config.last_attempt_warning = true
180
180
 
181
181
  # ==> Configuration for :recoverable
182
182
  #
@@ -12,6 +12,9 @@ en:
12
12
  save: 'Save'
13
13
  cancel: 'Cancel'
14
14
  clone: 'Clone'
15
+ launch_form_manager: 'Manage Form'
16
+ save_form_manager: 'Save Changes'
17
+ cancel_form_manager: 'Cancel'
15
18
  attribute:
16
19
  first_name: 'First Name'
17
20
  last_name: 'Last Name'
@@ -31,6 +34,13 @@ en:
31
34
  last_login: 'Last Logged In'
32
35
  active: 'Active'
33
36
  add_user: 'Add User'
37
+ deploy_hook:
38
+ environment: 'Environment'
39
+ add_deploy_hook: 'Add Deploy Hook'
40
+ new_deploy_hook: 'New Deploy Hook'
41
+ edit_deploy_hook: 'Edit Deploy Hook'
42
+ section_heading: 'Deploy Hooks'
43
+ section_helper_text: ''
34
44
  page:
35
45
  title: 'Pages'
36
46
  disabled_title: 'Disabled Admin'
@@ -41,7 +51,7 @@ en:
41
51
  error_end: 'to be taken to our home page.'
42
52
  hello: 'Hello'
43
53
  welcome: 'Welcome to Fae'
44
- no_objs_start: "You don'thave any objects setup to manage. If you need help getting started, check out the"
54
+ no_objs_start: "You don't have any objects setup to manage. If you need help getting started, check out the"
45
55
  no_objs_end: 'Quickstart Guide and Documentation site.'
46
56
  navbar:
47
57
  logout: 'Log Out'
@@ -52,6 +62,8 @@ en:
52
62
  jump_to: 'Jump to...'
53
63
  root_settings: 'Root Settings'
54
64
  no_results: 'No Results'
65
+ deployments: 'Deploy'
66
+ deploy_hooks: 'Deploy Hooks'
55
67
  changes:
56
68
  recent: 'Recent Changes'
57
69
  user: 'User'
@@ -69,6 +81,8 @@ en:
69
81
  last_day: 'Last Day'
70
82
  last_week: 'Last Week'
71
83
  last_month: 'Last Month'
84
+ on_prod: 'On Prod'
85
+ on_stage: 'On Stage'
72
86
  models:
73
87
  users: 'Users'
74
88
  types: 'Types'
@@ -76,6 +90,27 @@ en:
76
90
  user: 'User'
77
91
  type: 'Type'
78
92
  model: 'Model'
93
+ deploy:
94
+ page:
95
+ heading: 'Deploy'
96
+ ctas:
97
+ deploy: 'Deploy'
98
+ table:
99
+ past_heading: 'Past Deploys'
100
+ deploying_heading: 'Deploying'
101
+ deploying_helper: "After making changes in the CMS, click a deploy button above to push these changes to the respective front-end environment. Once your deployment posts to the “Past Deploys” table below, updates will be ready to review in the front-end environment.<br><br>Please note that each environment is distinct and will need to be deployed separately."
102
+ title: 'Activity'
103
+ deployed: 'Date/Time'
104
+ duration: 'Duration'
105
+ branch: 'Branch'
106
+ committer: 'Committer'
107
+ context: 'Environment'
108
+ state: 'State'
109
+ error_msg: 'Error Msg'
110
+ no_deploys: 'No deploys were found.'
111
+ changes:
112
+ production_heading: 'Changes since last production deploy'
113
+ staging_heading: 'Changes since last staging deploy'
79
114
  setup:
80
115
  prompt: 'Please create your super admin user.'
81
116
  password: 'Passwords must contain at least 8 characters.'
@@ -86,8 +121,9 @@ en:
86
121
  stage_url: 'Stage URL'
87
122
  logo_helper: 'Used on login page, 300x300px .jpg'
88
123
  images:
89
- alt_helper: 'Brief description of image contents, used in hover text and by visually impaired users.'
124
+ alt_helper: 'Read by search engines and visually impaired readers.'
90
125
  application:
126
+ activity_log_heading: 'Activity Log'
91
127
  user_absent: 'user no longer exists'
92
128
  no_logs: 'No logs available.'
93
129
  view_site: 'View Site'
@@ -111,7 +147,7 @@ en:
111
147
  paragraph_break: 'Paragraph break'
112
148
  paragraph_break_help: 'Adding a blank line in between your paragraphs makes a paragraph break.'
113
149
  seo_title: 'A descriptive page title of ~50-65 characters. Displayed in search engine results.'
114
- seo_description: 'A helpful page summary of 320 characters or less. Displayed in search engine results.'
150
+ seo_description: 'A helpful page summary of 200 characters or less. Displayed in search engine results.'
115
151
  search: 'Search %{search}'
116
152
  reset_search: 'Reset Search'
117
153
  apply_filters: 'Apply Filters'
@@ -41,7 +41,7 @@ zh-CN:
41
41
  error_end: 'to be taken to our home page.'
42
42
  hello: 'Hello'
43
43
  welcome: 'Welcome to Fae'
44
- no_objs_start: "You don'thave any objects setup to manage. If you need help getting started, check out the"
44
+ no_objs_start: "You don't have any objects setup to manage. If you need help getting started, check out the"
45
45
  no_objs_end: 'Quickstart Guide and Documentation site.'
46
46
  navbar:
47
47
  logout: 'Log Out'
@@ -86,7 +86,7 @@ zh-CN:
86
86
  stage_url: 'Stage URL'
87
87
  logo_helper: 'Used on login page, 300x300px .jpg'
88
88
  images:
89
- alt_helper: 'Brief description of image contents, used in hover text and by visually impaired users.'
89
+ alt_helper: 'Read by search engines and visually impaired readers.'
90
90
  application:
91
91
  user_absent: 'user no longer exists'
92
92
  no_logs: 'No logs available.'
data/config/routes.rb CHANGED
@@ -11,8 +11,10 @@ Fae::Engine.routes.draw do
11
11
  get 'logout' => '/devise/sessions#destroy', as: :destroy_user_session
12
12
  end
13
13
  resources :users
14
+ resources :deploy_hooks
14
15
 
15
16
  get 'settings' => 'users#settings', as: 'settings'
17
+ get 'deploy' => 'deploy#index', as: 'deploy'
16
18
  get 'help' => 'pages#help', as: 'help'
17
19
  get 'activity' => 'pages#activity_log', as: 'activity_log'
18
20
  post 'activity/filter' => 'pages#activity_log_filter', as: 'activity_log_filter'
@@ -38,7 +40,13 @@ Fae::Engine.routes.draw do
38
40
  get 'content_blocks/:slug' => '/admin/content_blocks#edit', as: 'edit_content_block'
39
41
  match 'content_blocks/:slug/update' => '/admin/content_blocks#update', via: [:put, :patch], as: 'update_content_block'
40
42
 
41
- # catch all 404
43
+ get 'form_managers/fields' => 'form_managers#fields', as: 'form_managers_fields'
44
+ post 'form_managers/update' => 'form_managers#update', as: 'form_managers_update'
45
+
46
+ get 'deploy/deploys_list' => 'deploy#deploys_list', as: 'deploy_deploys_list'
47
+ post 'deploy/deploy_site' => 'deploy#deploy_site', as: 'deploy_deploy_site'
48
+
49
+ ## catch all 404
42
50
  match "*path" => 'pages#error404', via: [:get, :post]
43
51
 
44
52
  end
@@ -34,7 +34,7 @@ class AddUserTable < ActiveRecord::Migration[4.2]
34
34
  t.string :first_name
35
35
  t.string :last_name
36
36
  t.integer :role_id
37
- t.boolean :active
37
+ t.boolean :active, :default => true, :null => false
38
38
  t.string :language
39
39
 
40
40
  t.timestamps
@@ -0,0 +1,11 @@
1
+ class CreateFaeFormManagers < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :fae_form_managers do |t|
4
+ t.string :form_manager_model_name, index: true
5
+ t.integer :form_manager_model_id, index: true
6
+ t.text :fields
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class CreateFaePublishHooks < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :fae_publish_hooks do |t|
4
+ t.string :url
5
+ t.string :environment, index: true
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class RenamePublishHooks < ActiveRecord::Migration[5.2]
2
+ def change
3
+ rename_table :fae_publish_hooks, :fae_deploy_hooks
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddPositionToDeployHooks < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :fae_deploy_hooks, :position, :integer
4
+ add_index :fae_deploy_hooks, :position
5
+ end
6
+ end
data/lib/fae/options.rb CHANGED
@@ -5,7 +5,7 @@ require_relative 'validation_helper_collection'
5
5
  module Fae
6
6
  # configurable defaults
7
7
  class << self
8
- mattr_accessor :devise_secret_key, :devise_mailer_sender, :dashboard_exclusions, :max_image_upload_size, :max_file_upload_size, :languages, :recreate_versions, :validation_helpers, :track_changes, :tracker_history_length, :slug_separator, :disabled_environments, :per_page, :use_cache
8
+ mattr_accessor :devise_secret_key, :devise_mailer_sender, :dashboard_exclusions, :max_image_upload_size, :max_file_upload_size, :languages, :recreate_versions, :validation_helpers, :track_changes, :tracker_history_length, :slug_separator, :disabled_environments, :per_page, :use_cache, :use_form_manager, :netlify
9
9
 
10
10
  self.devise_secret_key = ''
11
11
  self.devise_mailer_sender = 'change-me@example.com'
@@ -21,6 +21,8 @@ module Fae
21
21
  self.disabled_environments = []
22
22
  self.per_page = 25
23
23
  self.use_cache = false
24
+ self.use_form_manager = false
25
+ self.netlify = {}
24
26
  end
25
27
 
26
28
  # this function maps the vars from your app into your engine
@@ -32,4 +34,4 @@ module Fae
32
34
  Devise.mailer_sender = Fae.devise_mailer_sender
33
35
  Kaminari.config.default_per_page = Fae.per_page
34
36
  end
35
- end
37
+ end
data/lib/fae/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fae
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -4,6 +4,7 @@ module Fae
4
4
  argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
5
5
  class_option :namespace, type: :string, default: 'admin', desc: 'Sets the namespace of the generator'
6
6
  class_option :template, type: :string, default: 'slim', desc: 'Sets the template engine of the generator'
7
+ class_option :polymorphic, type: :boolean, default: false, desc: 'Makes the model and scaffolding polymorphic. parent-model is ignored if passed.'
7
8
 
8
9
  @@attributes_flat = []
9
10
  @@attribute_names = []
@@ -26,7 +27,11 @@ module Fae
26
27
  if is_attachment(arg)
27
28
  @@attachments << arg
28
29
  else
29
- @@attributes_flat << "#{arg.name}:#{arg.type}"
30
+ @@attributes_flat << "#{arg.name}:#{arg.type}" + (arg.has_index? ? ":index" : "")
31
+ end
32
+
33
+ if options.polymorphic
34
+ @@attributes_flat << "#{polymorphic_name}:references{polymorphic}"
30
35
  end
31
36
 
32
37
  if is_association(arg)
@@ -71,6 +76,7 @@ module Fae
71
76
  @attachments = @@attachments
72
77
  @has_position = @@has_position
73
78
  @display_field = @@display_field
79
+ @polymorphic_name = polymorphic_name
74
80
  template "views/index.html.#{options.template}", "app/views/#{options.namespace}/#{plural_file_name}/index.html.#{options.template}"
75
81
  template "views/_form.html.#{options.template}", "app/views/#{options.namespace}/#{plural_file_name}/_form.html.#{options.template}"
76
82
  copy_file "views/new.html.#{options.template}", "app/views/#{options.namespace}/#{plural_file_name}/new.html.#{options.template}"
@@ -195,5 +201,9 @@ RUBY
195
201
  [:image,:file].include?(arg.type)
196
202
  end
197
203
 
204
+ def polymorphic_name
205
+ "#{file_name.underscore}able"
206
+ end
207
+
198
208
  end
199
209
  end
@@ -21,10 +21,12 @@ module Fae
21
21
  inject_model_attachments
22
22
  inject_position_scope
23
23
  inject_parent_info if options.parent_model.present?
24
+ inject_polymorphic_info if options.polymorphic
24
25
  end
25
26
 
26
27
  def generate_nested_controller_file
27
28
  @attachments = @@attachments
29
+ @polymorphic_name = polymorphic_name
28
30
  template "controllers/nested_scaffold_controller.rb", "app/controllers/#{options.namespace}/#{file_name.pluralize}_controller.rb"
29
31
  end
30
32
 
@@ -44,6 +46,17 @@ module Fae
44
46
  def fae_nested_parent
45
47
  :#{options.parent_model.underscore}
46
48
  end
49
+ RUBY
50
+ end
51
+ end
52
+
53
+ def inject_polymorphic_info
54
+ inject_into_file "app/models/#{file_name}.rb", after: "BaseModelConcern\n" do <<-RUBY
55
+
56
+ def fae_nested_parent
57
+ :#{polymorphic_name}
58
+ end
59
+
47
60
  RUBY
48
61
  end
49
62
  end
@@ -3,4 +3,4 @@
3
3
  // or just add your javascript directly to this file
4
4
 
5
5
  // Uncomment the following line if you want to use Trumbowyg HTML Editor
6
- // //= require fae/vendor/trumbowyg
6
+ // //= require fae/vendor/trumbowyg
@@ -1,5 +1,19 @@
1
1
  module <%= options.namespace.capitalize %>
2
2
  class <%= class_name.pluralize %>Controller < Fae::NestedBaseController
3
+
4
+ <% if options.polymorphic %>
5
+ def new
6
+ @item = @klass.new
7
+ raise_undefined_parent if @item.fae_nested_foreign_key.blank?
8
+
9
+ item_id = params[:item_id].to_i || nil
10
+ item_class = params[:item_class] || nil
11
+ @item.send("<%= @polymorphic_name %>_id=", item_id)
12
+ @item.send("<%= @polymorphic_name %>_type=", item_class)
13
+ build_assets
14
+ end
15
+ <% end %>
16
+
3
17
  <% if @attachments.present? %>
4
18
  private
5
19
 
@@ -60,4 +60,19 @@ Fae.setup do |config|
60
60
  # on the parent app
61
61
  # Defaults to false
62
62
  # config.use_cache = true
63
- end
63
+
64
+ ## use_form_manager
65
+ # Enable Manage Form buttons in form headers
66
+ # Defaults to false
67
+ # config.use_form_manager = true
68
+
69
+ ## Netlify configs
70
+ # Environment variables are recommended for any sensitive Netlify configuration details.
71
+ # config.netlify = {
72
+ # api_user: 'netlify-api-user',
73
+ # api_token: 'netlify-api-token',
74
+ # site: 'site-name-in-netlify',
75
+ # site_id: 'site-id-in-netlify',
76
+ # api_base: 'https://api.netlify.com/api/v1/'
77
+ # }
78
+ end
@@ -1,4 +1,13 @@
1
- = simple_form_for(['admin', @item]) do |f|
1
+ ruby:
2
+ form_options = {
3
+ html: {
4
+ data: {
5
+ form_manager_model: @item.fae_form_manager_model_name,
6
+ form_manager_info: (@form_manager.present? ? @form_manager.to_json : nil)
7
+ }
8
+ }
9
+ }
10
+ = simple_form_for([:admin, @item], form_options) do |f|
2
11
  == render 'fae/shared/form_header', header: @klass_name
3
12
 
4
13
  main.content
@@ -1,4 +1,18 @@
1
- = simple_form_for(['<%= options.namespace %>', @item], html: {multipart: true, novalidate: true, class: 'js-file-form'}, remote: true, data: {type: "html"}) do |f|
1
+ ruby:
2
+ form_options = {
3
+ html: {
4
+ multipart: true,
5
+ novalidate: true,
6
+ class: 'js-file-form',
7
+ remote: true,
8
+ data: {
9
+ type: "html",
10
+ form_manager_model: @item.fae_form_manager_model_name,
11
+ form_manager_info: (@form_manager.present? ? @form_manager.to_json : nil)
12
+ }
13
+ }
14
+ }
15
+ = simple_form_for(['<%= options.namespace %>', @item], form_options) do |f|
2
16
  <% @form_attrs.each do |attr| -%>
3
17
  = fae_input f, :<%= attr %>
4
18
  <% end -%>
@@ -1,4 +1,18 @@
1
- = simple_form_for(['<%= options.namespace %>', @item], html: {multipart: true, novalidate: true, class: 'js-file-form'}, remote: true, data: {type: "html"}) do |f|
1
+ ruby:
2
+ form_options = {
3
+ html: {
4
+ multipart: true,
5
+ novalidate: true,
6
+ class: 'js-file-form',
7
+ remote: true,
8
+ data: {
9
+ type: "html",
10
+ form_manager_model: @item.fae_form_manager_model_name,
11
+ form_manager_info: (@form_manager.present? ? @form_manager.to_json : nil)
12
+ }
13
+ }
14
+ }
15
+ = simple_form_for([:admin, @item], form_options) do |f|
2
16
  <% @form_attrs.each do |attr| -%>
3
17
  = fae_input f, :<%= attr %>
4
18
  <% end -%>
@@ -9,7 +23,10 @@
9
23
  = fae_file_form f, :<%= attachment.name -%>
10
24
  <% end -%>
11
25
  <% end -%>
12
- <% if options.parent_model.present? %>
26
+ <% if options.polymorphic %>
27
+ = f.hidden_field :<%= @polymorphic_name %>_id
28
+ = f.hidden_field :<%= @polymorphic_name %>_type
29
+ <% elsif options.parent_model.present? %>
13
30
  = f.hidden_field :<%= options.parent_model.underscore %>_id
14
31
  <% end -%>
15
32
 
@@ -1,4 +1,16 @@
1
- = simple_form_for @item, url: fae.update_content_block_path(slug: @item.slug), method: :put do |f|
1
+ ruby:
2
+ form_options = {
3
+ url: fae.update_content_block_path(slug: @item.slug),
4
+ method: :put,
5
+ html: {
6
+ data: {
7
+ form_manager_model: @item.fae_form_manager_model_name,
8
+ form_manager_model_id: @item.fae_form_manager_model_id,
9
+ form_manager_info: (@form_manager.present? ? @form_manager.to_json : nil)
10
+ }
11
+ }
12
+ }
13
+ = simple_form_for @item, form_options do |f|
2
14
  == render 'fae/shared/form_header', header: @item
3
15
 
4
16
  main.content