chr 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.scss-style.yml +3 -3
  3. data/{LICENSE → LICENSE.md} +0 -0
  4. data/README.md +24 -10
  5. data/app/assets/javascripts/chr/list_tabs.coffee +1 -2
  6. data/app/assets/javascripts/chr/view_tabs.coffee +7 -6
  7. data/app/assets/stylesheets/chr/layout.scss +15 -2
  8. data/app/assets/stylesheets/chr/themes/basic.scss +8 -16
  9. data/chr.gemspec +33 -34
  10. data/lib/chr.rb +9 -12
  11. data/lib/chr/version.rb +1 -1
  12. metadata +8 -51
  13. data/app/assets/javascripts/vendor/slip.js +0 -804
  14. data/bin/chr +0 -13
  15. data/docs/bootstrap.md +0 -23
  16. data/docs/demo.png +0 -0
  17. data/docs/notes.md +0 -3
  18. data/docs/rails.md +0 -233
  19. data/lib/chr/app_builder.rb +0 -378
  20. data/lib/chr/generators/app_generator.rb +0 -211
  21. data/lib/generators/chr/controller_generator.rb +0 -18
  22. data/templates/Gemfile.erb +0 -41
  23. data/templates/Procfile +0 -1
  24. data/templates/README.md.erb +0 -45
  25. data/templates/_analytics.html.erb +0 -1
  26. data/templates/_flashes.html.erb +0 -7
  27. data/templates/_javascript.html.erb +0 -5
  28. data/templates/application.coffee +0 -2
  29. data/templates/application.scss +0 -1
  30. data/templates/application.yml +0 -6
  31. data/templates/application_gitignore +0 -15
  32. data/templates/application_layout.html.erb.erb +0 -17
  33. data/templates/bin_setup.erb +0 -35
  34. data/templates/body_class_helper.rb +0 -15
  35. data/templates/bundler_audit.rake +0 -12
  36. data/templates/carrierwave.rb +0 -21
  37. data/templates/character_admin.coffee.erb +0 -38
  38. data/templates/character_admin.scss +0 -14
  39. data/templates/character_admin_index.html.erb +0 -5
  40. data/templates/character_admin_layout.html.erb.erb +0 -21
  41. data/templates/character_base_controller.rb +0 -14
  42. data/templates/dev.rake +0 -12
  43. data/templates/devise_overrides_passwords_controller.rb +0 -11
  44. data/templates/devise_overrides_passwords_edit.html.erb +0 -31
  45. data/templates/devise_overrides_passwords_new.html.erb +0 -19
  46. data/templates/devise_overrides_sessions_controller.rb +0 -20
  47. data/templates/devise_overrides_sessions_new.html.erb +0 -29
  48. data/templates/errors.rb +0 -34
  49. data/templates/json_encoding.rb +0 -1
  50. data/templates/puma.rb +0 -18
  51. data/templates/routes.rb +0 -86
  52. data/templates/sample.env +0 -6
  53. data/templates/secrets.yml +0 -14
  54. data/templates/smtp.rb +0 -9
  55. data/templates/staging.rb +0 -5
data/bin/chr DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'pathname'
3
-
4
- source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
- $LOAD_PATH << source_path
6
-
7
- require 'chr'
8
-
9
- templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
10
- Chr::AppGenerator.source_root templates_root
11
- Chr::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
12
-
13
- Chr::AppGenerator.start
@@ -1,23 +0,0 @@
1
- # Character
2
-
3
- ## Bootstrap Data
4
-
5
- Bootstrapped data configuration example with disabled item updates and pagination:
6
-
7
- ```coffee
8
- postsConfig = (data) ->
9
- itemTitleField: 'title'
10
- disableUpdateItems: true
11
- objects: data.posts
12
- arrayStore: new RailsArrayStore({
13
- resource: 'post'
14
- path: '/admin/posts'
15
- sortBy: 'title'
16
- pagination: false
17
- })
18
- formSchema:
19
- title: { type: 'string' }
20
- body: { type: 'text' }
21
- ```
22
-
23
- ```disableUpdateItems``` — do not update items in the list while navigation, ```objects``` — provides initial (bootstrapped) array of objects to be added to the list, ```pagination``` — disable pagination for list. If attached as modules root list, you can access store data with: ```chr.modules.posts.arrayStore.data()```.
Binary file
@@ -1,3 +0,0 @@
1
- # Notes
2
-
3
- 1. Consider replace ```slip.js``` with [sortable.js](https://github.com/RubaXa/Sortable)
@@ -1,233 +0,0 @@
1
- # Character
2
-
3
- ## Rails Setup
4
-
5
- An example of admin implementation setup for [Rails](https://github.com/rails/rails) app that uses [Mongoid](https://github.com/mongoid/mongoid) stack.
6
-
7
-
8
- ### Gems
9
-
10
- Add to following gems to ```Gemfile```:
11
-
12
- gem "devise"
13
- gem "mongosteen"
14
- gem "chr"
15
-
16
- This example uses ```devise``` for admins authentication.
17
-
18
-
19
- ### Admin authentication
20
-
21
- Start with running [devise](https://github.com/plataformatec/devise) generator:
22
-
23
- rails generate devise:install
24
-
25
- Setup ```Admin``` model with devise generator:
26
-
27
- rails generate devise admin
28
-
29
- Here is an example of basic ```app/models/admin.rb``` model that provides email/password authentication:
30
-
31
- ```ruby
32
- class Admin
33
- include Mongoid::Document
34
- include Mongoid::Timestamps
35
- include Mongoid::SerializableId
36
-
37
- devise :database_authenticatable,
38
- :rememberable,
39
- :authentication_keys => [ :email ]
40
-
41
- ## Database authenticatable
42
- field :email, type: String, default: ""
43
- field :encrypted_password, type: String, default: ""
44
-
45
- ## Rememberable
46
- field :remember_created_at, type: Time
47
- end
48
- ```
49
-
50
- When models are ready, setup controllers, views and configure routes.
51
-
52
- Base admin controller ```app/controllers/admin/base_controller.rb``` looks like this:
53
-
54
- ```ruby
55
- class Admin::BaseController < ActionController::Base
56
- protect_from_forgery
57
-
58
- if Rails.env.production?
59
- before_action :authenticate_admin!
60
- end
61
-
62
- def index
63
- render '/admin/index', layout: 'admin'
64
- end
65
-
66
- def bootstrap_data
67
- render json: {}
68
- end
69
- end
70
- ```
71
-
72
- Notes on code above:
73
-
74
- 1. Authentication is not required when running in development or testing environment;
75
- 2. Need to setup ```index``` view and ```admin``` layout to render admin app;
76
- 3. ```bootstrap_data``` is a placeholder for objects that might be required to be loaded when app starts.
77
-
78
- Devise would require a custom ```SessionController``` implementation in ```app/controllers/admin/devise_overrides/session_controller.rb```. ```SessionController``` sets ```admin``` layout to be used for devise views rendering.
79
-
80
- ```ruby
81
- class Admin::DeviseOverrides::SessionsController < Devise::SessionsController
82
- layout 'admin'
83
- end
84
- ```
85
-
86
- Admin app layout ```app/views/layouts/admin.html.erb```:
87
-
88
- ```erb
89
- <!doctype html>
90
- <html>
91
- <head>
92
- <meta charset="utf-8">
93
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
94
- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
95
- <meta name="apple-mobile-web-app-capable" content="yes">
96
- <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
97
- <title>Admin</title>
98
- <%= csrf_meta_tags %>
99
- <%= stylesheet_link_tag :admin, media: "all" %>
100
- </head>
101
-
102
- <%= yield %>
103
- </html>
104
- ```
105
-
106
- Admin index view ```app/views/admin/index.html.erb```:
107
-
108
- ```erb
109
- <body class='loading'>
110
-
111
- <% admin_email = Rails.env.production? ? current_admin.email : 'developer@example.com' %>
112
-
113
- <%= link_to 'Sign Out', destroy_admin_session_path, 'data-admin-email' => admin_email,
114
- method: :delete,
115
- style: 'display:none;', class: 'menu-logout' %>
116
- </body>
117
-
118
- <%= javascript_include_tag :admin %>
119
- ```
120
-
121
- New session view for devise ```app/views/admin/devise_overrides/sessions/new.html.erb```:
122
-
123
- ```erb
124
- <body class='sign-in'>
125
- <h2>Sign In</h2>
126
-
127
- <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
128
- <% if alert %>
129
- <p class="error"><%= alert.gsub('username', 'email').gsub('or sign up', '') %></p>
130
- <% end %>
131
-
132
- <div class="form-inputs">
133
- <%= f.input :email, required: true, autofocus: true %>
134
- <%= f.input :password, required: true %>
135
-
136
- <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
137
- </div>
138
-
139
- <div class="form-actions">
140
- <%= f.button :submit, "Sign In" %>
141
- </div>
142
- <% end %>
143
- </body>
144
- ```
145
-
146
- Now connect admin and devise in ```config/routes.rb``` with:
147
-
148
- ```ruby
149
- devise_for :admins, path: "admin", controllers: { sessions: "admin/devise_overrides/sessions" }
150
- namespace :admin do
151
- get '/' => 'base#index'
152
- get '/bootstrap.json' => 'base#bootstrap_data'
153
- end
154
- ```
155
-
156
-
157
- ### Character setup
158
-
159
- Three pieces to be configured here.
160
-
161
- **First**: create ```app/assets/javascripts/admin.coffee``` with empty ```modules``` configuration:
162
-
163
- ```coffee
164
- #= require jquery
165
- #= require jquery_ujs
166
- #= require chr
167
-
168
- $ ->
169
- $.get '/admin/bootstrap.json', (response) ->
170
- config =
171
- modules: {}
172
-
173
- $('body').removeClass('loading')
174
- chr.start(config)
175
-
176
- # append signout button to the end of sidebar menu
177
- $('a[data-method=delete]').appendTo(".sidebar .menu").show()
178
- ```
179
-
180
- **Second**: create foundation for style customization in ```app/assets/stylesheets/admin.scss```:
181
-
182
- ```scss
183
- @charset "utf-8";
184
-
185
- @import "normalize-rails";
186
- @import "chr";
187
- @import "admin/signin";
188
- ```
189
-
190
- Last import in the code above is optional. But here is a default source for it as well ```app/assets/stylesheets/admin/chr/_signin.scss```:
191
-
192
- ```scss
193
- .sign-in {
194
- margin: 2em; max-width: 18em;
195
-
196
- h2 { text-transform: uppercase; color: $black; }
197
- input { @include no-outline; }
198
- label { color: $black; }
199
- .input { margin-bottom: .75em; }
200
-
201
- .input input[type=checkbox] { margin-right: .5em; }
202
-
203
- .input input.email, .input input.password {
204
- float: right; margin: -2px 0 0; width: 12em;
205
- border: 0; border-bottom: 1px solid $contrastColor;
206
- }
207
-
208
- .input.boolean { margin-top: 1.25em; }
209
-
210
- .form-actions input {
211
- width: 100%; padding: 1em 2em; margin-top: .75em;
212
- color: $white; background-color: $positiveColor; border: 0;
213
- }
214
- }
215
-
216
- ```
217
-
218
- **Third**: make sure admin assets are precompiled on production, include ```admin.js``` and ```admin.css``` in ```config/initializers/assets.rb```:
219
-
220
- ```ruby
221
- Rails.application.config.assets.precompile += %w( admin.js admin.css )
222
- ```
223
-
224
- At this point initial setup for admin app is finished and it could be accessed via: ```localhost:3000/admin```.
225
-
226
-
227
- ### Add models
228
-
229
- To be continued...
230
-
231
-
232
-
233
-
@@ -1,378 +0,0 @@
1
- module Chr
2
- class AppBuilder < Rails::AppBuilder
3
-
4
- def readme
5
- template 'README.md.erb', 'README.md'
6
- end
7
-
8
-
9
- def replace_gemfile
10
- remove_file 'Gemfile'
11
- template 'Gemfile.erb', 'Gemfile'
12
- end
13
-
14
-
15
- def set_ruby_to_version_being_used
16
- create_file '.ruby-version', "#{Chr::RUBY_VERSION}\n"
17
- end
18
-
19
-
20
- def raise_on_delivery_errors
21
- replace_in_file 'config/environments/development.rb',
22
- 'raise_delivery_errors = false', 'raise_delivery_errors = true'
23
- end
24
-
25
-
26
- def raise_on_unpermitted_parameters
27
- config = <<-RUBY
28
- config.action_controller.action_on_unpermitted_parameters = :raise
29
- RUBY
30
-
31
- inject_into_class "config/application.rb", "Application", config
32
- end
33
-
34
-
35
- def provide_setup_script
36
- template "bin_setup.erb", "bin/setup", port_number: port, force: true
37
- run "chmod a+x bin/setup"
38
- end
39
-
40
-
41
- def provide_dev_prime_task
42
- copy_file 'dev.rake', 'lib/tasks/dev.rake'
43
- end
44
-
45
-
46
- def configure_generators
47
- config = <<-RUBY
48
-
49
- config.generators do |generate|
50
- generate.helper false
51
- generate.javascript_engine false
52
- generate.stylesheets false
53
- end
54
-
55
- RUBY
56
-
57
- inject_into_class 'config/application.rb', 'Application', config
58
- end
59
-
60
-
61
- def configure_smtp
62
- copy_file 'smtp.rb', 'config/smtp.rb'
63
-
64
- prepend_file 'config/environments/production.rb',
65
- %{require Rails.root.join("config/smtp")\n}
66
-
67
- config = <<-RUBY
68
-
69
- config.action_mailer.delivery_method = :smtp
70
- config.action_mailer.smtp_settings = SMTP_SETTINGS
71
- RUBY
72
-
73
- inject_into_file 'config/environments/production.rb', config,
74
- :after => 'config.action_mailer.raise_delivery_errors = false'
75
- end
76
-
77
-
78
- def configure_rack_timeout
79
- rack_timeout_config = <<-RUBY
80
- Rack::Timeout.timeout = (ENV["RACK_TIMEOUT"] || 10).to_i
81
- RUBY
82
-
83
- append_file "config/environments/production.rb", rack_timeout_config
84
- end
85
-
86
-
87
- def enable_rack_canonical_host
88
- config = <<-RUBY
89
-
90
- # Ensure requests are only served from one, canonical host name
91
- config.middleware.use Rack::CanonicalHost, ENV.fetch("HOST")
92
- RUBY
93
-
94
- inject_into_file(
95
- "config/environments/production.rb",
96
- config,
97
- after: serve_static_files_line
98
- )
99
- end
100
-
101
- def enable_rack_deflater
102
- config = <<-RUBY
103
-
104
- # Enable deflate / gzip compression of controller-generated responses
105
- config.middleware.use Rack::Deflater
106
- RUBY
107
-
108
- inject_into_file(
109
- "config/environments/production.rb",
110
- config,
111
- after: serve_static_files_line
112
- )
113
- end
114
-
115
-
116
- def setup_asset_host
117
- replace_in_file 'config/environments/production.rb',
118
- "# config.action_controller.asset_host = 'http://assets.example.com'",
119
- 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST")'
120
-
121
- replace_in_file 'config/initializers/assets.rb',
122
- "config.assets.version = '1.0'",
123
- 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
124
-
125
- inject_into_file(
126
- "config/environments/production.rb",
127
- ' config.static_cache_control = "public, max-age=#{1.year.to_i}"',
128
- after: serve_static_files_line
129
- )
130
- end
131
-
132
-
133
- def setup_staging_environment
134
- staging_file = 'config/environments/staging.rb'
135
- copy_file 'staging.rb', staging_file
136
-
137
- config = <<-RUBY
138
-
139
- Rails.application.configure do
140
- # ...
141
- end
142
- RUBY
143
-
144
- append_file staging_file, config
145
- end
146
-
147
-
148
- def setup_secret_token
149
- template 'secrets.yml', 'config/secrets.yml', force: true
150
- end
151
-
152
-
153
- def create_partials_directory
154
- empty_directory 'app/views/application'
155
- end
156
-
157
-
158
- def create_shared_analytics
159
- copy_file '_analytics.html.erb', 'app/views/application/_analytics.html.erb'
160
- end
161
-
162
-
163
- def create_shared_flashes
164
- copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
165
- end
166
-
167
-
168
- def create_shared_javascripts
169
- copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
170
- end
171
-
172
-
173
- def create_application_layout
174
- template 'application_layout.html.erb.erb',
175
- 'app/views/layouts/application.html.erb',
176
- force: true
177
- end
178
-
179
-
180
- def create_body_class_helper
181
- copy_file 'body_class_helper.rb', 'app/helpers/body_class_helper.rb'
182
- end
183
-
184
-
185
- def configure_action_mailer
186
- action_mailer_host "development", %{"localhost:#{ port }"}
187
- action_mailer_host "test", %{ "www.example.com" }
188
- action_mailer_host "staging", %{ ENV.fetch("HOST") }
189
- action_mailer_host "production", %{ ENV.fetch("HOST") }
190
-
191
- configure_environment "production", 'config.action_mailer.asset_host = "http://#{ ENV.fetch("ASSET_HOST") }"'
192
- end
193
-
194
-
195
- def configure_puma
196
- copy_file "puma.rb", "config/puma.rb"
197
- end
198
-
199
-
200
- def setup_foreman
201
- copy_file 'sample.env', '.sample.env'
202
- copy_file 'Procfile', 'Procfile'
203
- end
204
-
205
-
206
- def setup_stylesheets
207
- remove_file "app/assets/javascripts/application.js"
208
- copy_file "application.coffee",
209
- "app/assets/javascripts/application.coffee"
210
- end
211
-
212
-
213
- def setup_javascripts
214
- remove_file "app/assets/stylesheets/application.css"
215
- copy_file "application.scss",
216
- "app/assets/stylesheets/application.scss"
217
- end
218
-
219
-
220
- def copy_miscellaneous_files
221
- copy_file "errors.rb", "config/initializers/errors.rb"
222
- copy_file "json_encoding.rb", "config/initializers/json_encoding.rb"
223
- end
224
-
225
-
226
- def customize_error_pages
227
- meta_tags =<<-EOS
228
- <meta charset="utf-8" />
229
- <meta name="ROBOTS" content="NOODP" />
230
- <meta name="viewport" content="initial-scale=1" />
231
- EOS
232
-
233
- %w(500 404 422).each do |page|
234
- inject_into_file "public/#{page}.html", meta_tags, after: "<head>\n"
235
- replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
236
- end
237
- end
238
-
239
-
240
- def setup_devise
241
- generate 'devise:install'
242
-
243
- replace_in_file 'config/initializers/devise.rb',
244
- '# config.scoped_views = false',
245
- 'config.scoped_views = true'
246
-
247
- replace_in_file 'config/initializers/devise.rb',
248
- '# config.sign_out_all_scopes = true',
249
- 'config.sign_out_all_scopes = false'
250
- end
251
-
252
-
253
- def setup_character_routes
254
- remove_file 'config/routes.rb'
255
- copy_file 'routes.rb', 'config/routes.rb'
256
- end
257
-
258
-
259
- def setup_character_base_controller
260
- copy_file 'character_base_controller.rb', 'app/controllers/admin/base_controller.rb'
261
- end
262
-
263
-
264
- def configure_devise_for_character
265
- copy_file 'devise_overrides_passwords_controller.rb', 'app/controllers/admin/devise_overrides/passwords_controller.rb'
266
- copy_file 'devise_overrides_sessions_controller.rb', 'app/controllers/admin/devise_overrides/sessions_controller.rb'
267
-
268
- copy_file 'devise_overrides_passwords_edit.html.erb', 'app/views/admin/devise_overrides/passwords/edit.html.erb'
269
- copy_file 'devise_overrides_passwords_new.html.erb', 'app/views/admin/devise_overrides/passwords/new.html.erb'
270
- copy_file 'devise_overrides_sessions_new.html.erb', 'app/views/admin/devise_overrides/sessions/new.html.erb'
271
- end
272
-
273
-
274
- def setup_character_views
275
- template 'character_admin_layout.html.erb.erb',
276
- 'app/views/layouts/admin.html.erb',
277
- force: true
278
-
279
- copy_file 'character_admin_index.html.erb', 'app/views/admin/index.html.erb'
280
- end
281
-
282
-
283
- def setup_character_stylesheets
284
- template 'character_admin.coffee.erb', 'app/assets/javascripts/admin.coffee'
285
- end
286
-
287
-
288
- def setup_character_javascripts
289
- copy_file 'character_admin.scss', 'app/assets/stylesheets/admin.scss'
290
- end
291
-
292
-
293
- def setup_character_assets
294
- replace_in_file 'config/initializers/assets.rb',
295
- "# Rails.application.config.assets.precompile += %w( search.js )",
296
- 'Rails.application.config.assets.precompile += %w( admin.js admin.css )'
297
- end
298
-
299
-
300
- def setup_carrierwave
301
- copy_file "carrierwave.rb", "config/initializers/carrierwave.rb"
302
- end
303
-
304
-
305
- def init_git
306
- run 'git init'
307
- end
308
-
309
-
310
- def gitignore_files
311
- remove_file '.gitignore'
312
- template 'application_gitignore', '.gitignore'
313
- end
314
-
315
-
316
- def initialize_mongoid
317
- generate 'mongoid:config'
318
- append_file "config/mongoid.yml", """\nproduction:
319
- clients:
320
- default:
321
- uri: <%= ENV['MONGODB_URI'] %>"""
322
- end
323
-
324
-
325
- def setup_bundler_audit
326
- copy_file "bundler_audit.rake", "lib/tasks/bundler_audit.rake"
327
- append_file "Rakefile", %{\ntask default: "bundler:audit"\n}
328
- end
329
-
330
-
331
- def setup_spring
332
- bundle_command "exec spring binstub --all"
333
- end
334
-
335
-
336
- private
337
-
338
- def port
339
- 3000
340
- end
341
-
342
-
343
- def serve_static_files_line
344
- "config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?\n"
345
- end
346
-
347
-
348
- def replace_in_file(relative_path, find, replace)
349
- path = File.join(destination_root, relative_path)
350
- contents = IO.read(path)
351
-
352
- unless contents.gsub!(find, replace)
353
- raise "#{ find.inspect } not found in #{ relative_path }"
354
- end
355
-
356
- File.open(path, "w") { |file| file.write(contents) }
357
- end
358
-
359
-
360
- def action_mailer_host(rails_env, host)
361
- config = "config.action_mailer.default_url_options = { host: #{host} }"
362
- configure_environment(rails_env, config)
363
- end
364
-
365
-
366
- def configure_environment(rails_env, config)
367
- inject_into_file(
368
- "config/environments/#{rails_env}.rb",
369
- "\n\n #{config}",
370
- before: "\nend"
371
- )
372
- end
373
-
374
- end
375
- end
376
-
377
-
378
-