From 3e08313e70e7bb3e3bc3f606840da532a20a495e Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 9 Oct 2015 15:01:41 -0400 Subject: [PATCH 01/14] AtomicCms Scaffold Generator Why: In order to easily manage content on presentable pages, a generator is needed to do the initial legwork of creating and editing content. This change addresses the need by: Creating a scaffold generator to create a migration, model, controller, route, view, and admin resource for creating, displaying, and editing content. --- .../atomic_cms/scaffold/scaffold_generator.rb | 64 +++++++++++++++ lib/generators/atomic_cms/templates/admin.rb | 80 +++++++++++++++++++ .../atomic_cms/templates/controller.rb | 13 +++ lib/generators/atomic_cms/templates/model.rb | 4 + .../atomic_cms/templates/show.html.slim | 1 + 5 files changed, 162 insertions(+) create mode 100644 lib/generators/atomic_cms/scaffold/scaffold_generator.rb create mode 100644 lib/generators/atomic_cms/templates/admin.rb create mode 100644 lib/generators/atomic_cms/templates/controller.rb create mode 100644 lib/generators/atomic_cms/templates/model.rb create mode 100644 lib/generators/atomic_cms/templates/show.html.slim diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb new file mode 100644 index 0000000..defdf95 --- /dev/null +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -0,0 +1,64 @@ +require 'active_support/core_ext/string' + +module AtomicCms + module Generators + class ScaffoldGenerator < Rails::Generators::Base + argument :model_name, required: true + + desc <<-DESC.strip_heredoc + Create a model, controller, view, admin resource, and route. + DESC + + source_root File.expand_path("../../templates", __FILE__) + + def install_model_template + setup_scaffold + create_template({ + template_name: 'model.rb', + full_path: "app/models/#{@scaffold.model_file_name}.rb" + }) + end + + def install_controller_template + create_template({ + template_name: 'controller.rb', + full_path: "app/controllers/#{@scaffold.controller_file_name}_controller.rb" + }) + end + + def install_admin_template + create_template({ + template_name: 'admin.rb', + full_path: "app/admin/#{@scaffold.model_file_name}.rb" + }) + end + + def install_show_view_template + create_template({ + template_name: 'show.html.slim', + full_path: "app/views/#{@scaffold.view_folder}/show.html.slim" + }) + end + + def create_migration + puts "Migration incoming" + end + + private + + def setup_scaffold + @scaffold = OpenStruct.new( + model_name: model_name.singularize.titlecase, + model_file_name: model_name.singularize.downcase.underscore, + controller_name: model_name.pluralize.titlecase, + controller_file_name: model_name.pluralize.downcase, + view_folder: model_name.singularize.downcase.underscore + ) + end + + def create_template(options) + template( options[:template_name], options[:full_path] ) + end + end + end +end diff --git a/lib/generators/atomic_cms/templates/admin.rb b/lib/generators/atomic_cms/templates/admin.rb new file mode 100644 index 0000000..9722729 --- /dev/null +++ b/lib/generators/atomic_cms/templates/admin.rb @@ -0,0 +1,80 @@ +ActiveAdmin.register <%= @scaffold.model_name %> do + permit_params :content + + index do + selectable_column + column :created_at + column :updated_at + actions + end + + form html: { class: "edit-atomic-content" } do |f| + f.semantic_errors(*f.object.errors.keys) + + # new form + if !f.object.persisted? + f.inputs "Details" do + # f.input :title + end + f.actions + + # edit form + else + div class: "buttons" do + render partial: "admin/edit_buttons" + f.actions + end + + columns do + column span: 3 do + panel "Draft", id: "draft-panel" do + render partial: "components/edit", locals: { f: f } + end + end + + column id: "edit-node-column" do + div id: "edit-page" do + f.inputs "Page Details" do + f.input :title + f.input :path + end + end + + div id: "edit-node" do + f.inputs "Edit Element" do + div id: "edit-node-fields" + end + + f.actions do + li class: "move" do + a "Up", "#", class: "button", id: "move-node-up" + end + li class: "move" do + a "Down", "#", class: "button", id: "move-node-down" + end + li class: "cancel" do + a "Done", "#", class: "button", id: "done-edit-node" + end + li class: "delete" do + a "Delete", "#", class: "button", id: "delete-node" + end + end + end + end + end + end + end + + show do + div id: "component_preview" do + div page.content_render + end + end + + controller do + # permit all params until we can whitelist content_object + def permitted_params + params.permit! + end + end +end diff --git a/lib/generators/atomic_cms/templates/controller.rb b/lib/generators/atomic_cms/templates/controller.rb new file mode 100644 index 0000000..9834e6c --- /dev/null +++ b/lib/generators/atomic_cms/templates/controller.rb @@ -0,0 +1,13 @@ +require 'json' + +class <%= @scaffold.controller_name %>Controller < ApplicationController + def show + <%= "@#{@scaffold.model_file_name}" %> = <%= @scaffold.model_name %>.find(params[:id]) + if <%= "@#{@scaffold.model_file_name}" %> + render :show + else + render file: "#{Rails.root}/public/404.html", status: :not_found + Rails.logger.error "404 - Page #{request.path} cannot be found." + end + end +end diff --git a/lib/generators/atomic_cms/templates/model.rb b/lib/generators/atomic_cms/templates/model.rb new file mode 100644 index 0000000..b5da3d7 --- /dev/null +++ b/lib/generators/atomic_cms/templates/model.rb @@ -0,0 +1,4 @@ +class <%= @scaffold.model_name %> < ActiveRecord::Base + include AtomicCms::HasComponents + component_attr :content +end diff --git a/lib/generators/atomic_cms/templates/show.html.slim b/lib/generators/atomic_cms/templates/show.html.slim new file mode 100644 index 0000000..e367185 --- /dev/null +++ b/lib/generators/atomic_cms/templates/show.html.slim @@ -0,0 +1 @@ += <%= "@#{@scaffold.model_file_name}" %>.content_object.render From aff36a29b9be57f5bcf26cf9b28f58625ffaf264 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 9 Oct 2015 15:01:41 -0400 Subject: [PATCH 02/14] AtomicCms Scaffold Generator Why: In order to easily manage content on presentable pages, a generator is needed to do the initial legwork of creating and editing content. This change addresses the need by: Creating a scaffold generator to create a migration, model, controller, route, view, and admin resource for creating, displaying, and editing content. --- .../atomic_cms/scaffold/scaffold_generator.rb | 68 ++++++++++++++++ lib/generators/atomic_cms/templates/admin.rb | 80 +++++++++++++++++++ .../atomic_cms/templates/controller.rb | 13 +++ lib/generators/atomic_cms/templates/model.rb | 4 + .../atomic_cms/templates/show.html.slim | 1 + 5 files changed, 166 insertions(+) create mode 100644 lib/generators/atomic_cms/scaffold/scaffold_generator.rb create mode 100644 lib/generators/atomic_cms/templates/admin.rb create mode 100644 lib/generators/atomic_cms/templates/controller.rb create mode 100644 lib/generators/atomic_cms/templates/model.rb create mode 100644 lib/generators/atomic_cms/templates/show.html.slim diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb new file mode 100644 index 0000000..a2c0aa1 --- /dev/null +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -0,0 +1,68 @@ +require 'active_support/core_ext/string' + +module AtomicCms + module Generators + class ScaffoldGenerator < Rails::Generators::Base + argument :model_name, required: true + + desc <<-DESC.strip_heredoc + Create a model, controller, view, admin resource, and route. + DESC + + source_root File.expand_path("../../templates", __FILE__) + + def install_model_template + setup_scaffold + create_template({ + template_name: 'model.rb', + full_path: "app/models/#{@scaffold.model_file_name}.rb" + }) + end + + def install_controller_template + create_template({ + template_name: 'controller.rb', + full_path: "app/controllers/#{@scaffold.controller_file_name}_controller.rb" + }) + end + + def install_admin_template + create_template({ + template_name: 'admin.rb', + full_path: "app/admin/#{@scaffold.model_file_name}.rb" + }) + end + + def install_show_view_template + create_template({ + template_name: 'show.html.slim', + full_path: "app/views/#{@scaffold.view_folder}/show.html.slim" + }) + end + + def create_migration + generate "migration", "create#{@scaffold.model_name} name:string content:text" + end + + def set_route + inject_into_file "config/routes.rb", "\n resources :#{@scaffold.controller_file_name}\n", after: /\/atomic_cms"/ + end + + private + + def setup_scaffold + @scaffold = OpenStruct.new( + model_name: model_name.singularize.titlecase, + model_file_name: model_name.singularize.downcase.underscore, + controller_name: model_name.pluralize.titlecase, + controller_file_name: model_name.pluralize.downcase, + view_folder: model_name.singularize.downcase.underscore + ) + end + + def create_template(options) + template( options[:template_name], options[:full_path] ) + end + end + end +end diff --git a/lib/generators/atomic_cms/templates/admin.rb b/lib/generators/atomic_cms/templates/admin.rb new file mode 100644 index 0000000..9722729 --- /dev/null +++ b/lib/generators/atomic_cms/templates/admin.rb @@ -0,0 +1,80 @@ +ActiveAdmin.register <%= @scaffold.model_name %> do + permit_params :content + + index do + selectable_column + column :created_at + column :updated_at + actions + end + + form html: { class: "edit-atomic-content" } do |f| + f.semantic_errors(*f.object.errors.keys) + + # new form + if !f.object.persisted? + f.inputs "Details" do + # f.input :title + end + f.actions + + # edit form + else + div class: "buttons" do + render partial: "admin/edit_buttons" + f.actions + end + + columns do + column span: 3 do + panel "Draft", id: "draft-panel" do + render partial: "components/edit", locals: { f: f } + end + end + + column id: "edit-node-column" do + div id: "edit-page" do + f.inputs "Page Details" do + f.input :title + f.input :path + end + end + + div id: "edit-node" do + f.inputs "Edit Element" do + div id: "edit-node-fields" + end + + f.actions do + li class: "move" do + a "Up", "#", class: "button", id: "move-node-up" + end + li class: "move" do + a "Down", "#", class: "button", id: "move-node-down" + end + li class: "cancel" do + a "Done", "#", class: "button", id: "done-edit-node" + end + li class: "delete" do + a "Delete", "#", class: "button", id: "delete-node" + end + end + end + end + end + end + end + + show do + div id: "component_preview" do + div page.content_render + end + end + + controller do + # permit all params until we can whitelist content_object + def permitted_params + params.permit! + end + end +end diff --git a/lib/generators/atomic_cms/templates/controller.rb b/lib/generators/atomic_cms/templates/controller.rb new file mode 100644 index 0000000..9834e6c --- /dev/null +++ b/lib/generators/atomic_cms/templates/controller.rb @@ -0,0 +1,13 @@ +require 'json' + +class <%= @scaffold.controller_name %>Controller < ApplicationController + def show + <%= "@#{@scaffold.model_file_name}" %> = <%= @scaffold.model_name %>.find(params[:id]) + if <%= "@#{@scaffold.model_file_name}" %> + render :show + else + render file: "#{Rails.root}/public/404.html", status: :not_found + Rails.logger.error "404 - Page #{request.path} cannot be found." + end + end +end diff --git a/lib/generators/atomic_cms/templates/model.rb b/lib/generators/atomic_cms/templates/model.rb new file mode 100644 index 0000000..b5da3d7 --- /dev/null +++ b/lib/generators/atomic_cms/templates/model.rb @@ -0,0 +1,4 @@ +class <%= @scaffold.model_name %> < ActiveRecord::Base + include AtomicCms::HasComponents + component_attr :content +end diff --git a/lib/generators/atomic_cms/templates/show.html.slim b/lib/generators/atomic_cms/templates/show.html.slim new file mode 100644 index 0000000..e367185 --- /dev/null +++ b/lib/generators/atomic_cms/templates/show.html.slim @@ -0,0 +1 @@ += <%= "@#{@scaffold.model_file_name}" %>.content_object.render From a54d60ad6c32853239a08555f6cbe4c8d4fa0878 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 10:04:19 -0400 Subject: [PATCH 03/14] Update Atomic Cms Readme Why: The documentation is not correct and needs to be updated. This change addresses the need by: Updating the documentation so developers can easily use the CMS. --- README.md | 269 ++++-------------- .../atomic_cms/templates/controller.rb | 3 + 2 files changed, 54 insertions(+), 218 deletions(-) diff --git a/README.md b/README.md index af80ce2..e1e2e64 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,50 @@ on line 122 of the Active Admin initializer. Now you shall run the migration and seeds with: ```ruby -bundle exec rake db:setup +bundle exec rake db:create +bundle exec rake db:migrate ``` To verify, start the server and visit `localhost:3000/admin`. If you can login as `admin@example.com` with the password `password` you have successfully completed this step. +### Atomic CMS +#### Routes +Update your `config/routes.rb` to include the following: +```ruby +mount AtomicCms::Engine => "/atomic_cms", as: :atomic_cms +# If you are going to use a catch all route add the following line +get "*path", to: "pages#show", controller: "pages", as: :page, format: false +root to: 'pages#show', controller: "pages" +``` +The last two lines need to be at the **END** of your `routes.rb` file. + +##### Devise Authentication +Change the mount point above to be the following: +```ruby + authenticate :admin_user, -> (u) { u.admin? } do + mount AtomicCms::Engine => "/atomic_cms", as: :atomic_cms + end +``` +where `u` is the user and `admin?` the authentication method you have on that +user; it should return a boolean value. + +#### Scaffold Generator +Execute the following to create a model for your static pages: +```ruby +rails g atomic_cms:scaffold page +``` +*After this you should run your migrations.* + +Here is a list of everything that is generated for you: + +* Model +* Controller +* Active Admin Form +* Migration **Will need to be edited** +* Show View +* Route + ### Media Upload To install the media tables so that you can upload files until your heart is literally full run: @@ -104,234 +142,29 @@ this is properly imported: // // .status_tag { background: #6090DB; } ``` +*NOTE:* At the minimum, here is what is needed in `active_admin.scss`: +```scss +@import "active_admin/mixins"; +@import "active_admin/base"; +@import "atomic_cms"; -### Atomic CMS -#### Routes -Update your `config/routes.rb` to include the following: -```ruby -mount AtomicCms::Engine => "/atomic_cms", as: :atomic_cms -get "*path", to: "pages#show", controller: "pages", as: :page, format: false -root to: 'pages#show', controller: "pages" -``` -The last two lines need to be at the **END** of your `routes.rb` file. - -##### Devise Authentication -Change the mount point above to be the following: -```ruby - authenticate :admin_user, -> (u) { u.admin? } do - mount AtomicCms::Engine => "/atomic_cms", as: :atomic_cms - end -``` -where `u` is the user and `admin?` the authentication method you have on that -user; it should return a boolean value. - -#### Model -Execute the following to create a model for your static pages: -```ruby -rails g model pages title:string path:string content:text -``` -After this you should run your migrations. - -Update your Page model to match the following: -```ruby -class Page < ActiveRecord::Base - include AtomicCms::HasComponents - validates :title, :path, presence: true, uniqueness: true - component_attr :content -end -``` -#### Controller -Create a controller by running the following: -```ruby -rails g controller pages +#component_preview { + // Include application specific styling here +} ``` -Update your PagesController to match the following: -```ruby -require 'json' - -class PagesController < ApplicationController - def show - @page = Page.find_by_path(request.path) - if @page - render cms_template - else - render file: "#{Rails.root}/public/404.html", status: :not_found - Rails.logger.error "404 - Page #{request.path} cannot be found." - end - end - - private - def cms_template - File.join("pages", "page") - end -end -``` -#### Views -Create a view at `app/views/pages/page.html.slim` that contains the following: -```ruby -= @page.content_object.render -``` #### Components -Create the following component view at -`app/views/components/text_block.html.slim`: -```slim -.wrapper.large-margin - .text-block - .content-text - - if add_option(options[:header]) - h2 - = options[:header] - = markdown(options[:content]) +Generate components by executing the following: ``` -Create the following component class at `app/components/text_block_component.rb`: -```ruby -class TextBlockComponent < AtomicAssets::Component - def edit - rtn = cms_fields(field_types) - rtn << h.component(:text_block, field_previews).render - rtn.html_safe - end - - protected - - def field_previews - { - header: "{{preview.header}}", - content: markdown_preview('preview.content') - } - end - - def field_types - { - header: { field_type: "text" }, - content: { field_type: "markdown" } - } - end -end +rails g atomic_assets:component text_block ``` -Add the following to `app/assets/stylesheets/components/_text_block.scss`: -```scss -.text-block{ - position: relative; - .content-text{ - ul{ - margin-left: 10px; - padding-left: 0px; - position: relative; - display: inline-block; - li{ - list-style: disc; - margin-left: 20px; - } - } - } - &:before { - content: ''; - display: inline-block; - height: 100%; - vertical-align: middle; - margin-right: -0.25em; /* Adjusts for spacing */ - } -} -``` -### More Active Admin -In order to add components to a page, create -`app/views/admin/_edit_buttons.html.slim` and make it match the following: +In order for components to be utilized when managing content, a partial needs to +be created similar to the following at `app/views/admin/_edit_buttons.html.slim`: ```slim ol.edit-buttons li = link_to 'Text Block', atomic_cms.edit_component_path('text_block'), class: 'button' ``` -Create an admin page for the Pages model at `app/admin/page.rb` and make it -match the following: -```ruby -ActiveAdmin.register Page do - permit_params :title, :path, :content - - index do - selectable_column - column :path - column :title - column :created_at - column :updated_at - actions - end - - form html: { class: "edit-atomic-content" } do |f| - f.semantic_errors(*f.object.errors.keys) - - # new form - if !f.object.persisted? - f.inputs "Page Details" do - f.input :title - f.input :path - end - f.actions - - # edit form - else - div class: "buttons" do - render partial: "admin/edit_buttons" - f.actions - end - - columns do - column span: 3 do - panel "Draft", id: "draft-panel" do - render partial: "components/edit", locals: { f: f } - end - end - - column id: "edit-node-column" do - div id: "edit-page" do - f.inputs "Page Details" do - f.input :cms_type, type: :hidden, - input_html: { value: "page", id: "cms_type" } - f.input :title - f.input :path - end - end - - div id: "edit-node" do - f.inputs "Edit Element" do - div id: "edit-node-fields" - end - - f.actions do - li class: "move" do - a "Up", "#", class: "button", id: "move-node-up" - end - li class: "move" do - a "Down", "#", class: "button", id: "move-node-down" - end - li class: "cancel" do - a "Done", "#", class: "button", id: "done-edit-node" - end - li class: "delete" do - a "Delete", "#", class: "button", id: "delete-node" - end - end - end - end - end - end - end - - show do - div id: "component_preview" do - div page.content_render - end - end - - controller do - # permit all params until we can whitelist content_object - def permitted_params - params.permit! - end - end -end -``` #### Config Update `config/application.rb` to include: ```ruby diff --git a/lib/generators/atomic_cms/templates/controller.rb b/lib/generators/atomic_cms/templates/controller.rb index 9834e6c..c40fb95 100644 --- a/lib/generators/atomic_cms/templates/controller.rb +++ b/lib/generators/atomic_cms/templates/controller.rb @@ -2,7 +2,10 @@ class <%= @scaffold.controller_name %>Controller < ApplicationController def show + # Standard find by ID <%= "@#{@scaffold.model_file_name}" %> = <%= @scaffold.model_name %>.find(params[:id]) + # Find by path + <%= "@#{@scaffold.model_file_name}" %> = <%= @scaffold.model_name %>.find_by_path(request.path) if <%= "@#{@scaffold.model_file_name}" %> render :show else From 4c3f764a119b348584653f9fb509920a6c75892f Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 10:26:39 -0400 Subject: [PATCH 04/14] Style Dependencies Why: Bourbon, bitters, and neat are required in the atomic_cms scss file so the dependency needs to be established. This change addresses the need by: Document the dependency in the gemspec and update the `active_admin.scss` entry list. --- atomic_cms.gemspec | 7 +++++-- lib/generators/atomic_cms/assets/assets_generator.rb | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/atomic_cms.gemspec b/atomic_cms.gemspec index c47598a..4e49426 100644 --- a/atomic_cms.gemspec +++ b/atomic_cms.gemspec @@ -1,12 +1,12 @@ Gem::Specification.new do |s| s.name = 'atomic_cms' - s.version = '0.2.1' + s.version = '0.2.2' s.date = '2015-06-19' s.summary = 'Atomic CMS' s.description = 'Live CMS powered by atomic assets.' s.authors = ['Don Humphreys'] s.email = 'dhumphreys88@gmail.com' - s.files = `git ls-files lib`.split(/\n/) + s.files = `git ls-files`.split(/\n/) s.test_files = Dir['spec/**/*'] # s.homepage = 'http://rubygems.org/gems/atomic_cms' # s.license = 'MIT' @@ -19,6 +19,9 @@ Gem::Specification.new do |s| s.add_dependency 'redcarpet', '~> 3.3' s.add_dependency 'slim-rails', '~> 3.0' s.add_dependency 'paperclip', '~> 4.3' + s.add_dependency 'bourbon', '~> 4.2.6' + s.add_dependency 'neat', '~> 1.7.2' + s.add_dependency 'bitters', '~> 1.10' s.add_development_dependency 'rspec-core', '~> 3.3' s.add_development_dependency 'rspec-expectations', '~> 3.3' diff --git a/lib/generators/atomic_cms/assets/assets_generator.rb b/lib/generators/atomic_cms/assets/assets_generator.rb index 9bf9083..2d3024b 100644 --- a/lib/generators/atomic_cms/assets/assets_generator.rb +++ b/lib/generators/atomic_cms/assets/assets_generator.rb @@ -14,9 +14,18 @@ def initialize_active_admin_javascript def initialize_active_admin_scss scss_asset = 'app/assets/stylesheets/active_admin.scss' entries = [ - '@import "atomic_cms"', + '@import "bourbon";', + '@import "neat";', + '@import "base/variables";', + '@import "base/grid-settings";', + '@import "atomic_cms";', '', '#component_preview {', + ' @import "base/buttons";', + ' @import "base/forms";', + ' @import "base/lists";', + ' @import "base/tables";', + ' @import "base/typography";', ' // When editing a page through Atomic CMS', ' // images with broken links should not be displayed.', ' img[src="image"] { display:none !important; }', From e392fe457d7b26f8e02b00badb4f2fb2aee3e66b Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 10:33:52 -0400 Subject: [PATCH 05/14] Bitters Setup Why: When the assets are first created, bitters may not have been installed and will cause an error when the developer tries to start the server and visit the admin page. This change addresses the need by: Install bitters for the developer. --- lib/generators/atomic_cms/assets/assets_generator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/generators/atomic_cms/assets/assets_generator.rb b/lib/generators/atomic_cms/assets/assets_generator.rb index 2d3024b..3336dcb 100644 --- a/lib/generators/atomic_cms/assets/assets_generator.rb +++ b/lib/generators/atomic_cms/assets/assets_generator.rb @@ -1,6 +1,10 @@ module AtomicCms module Generators class AssetsGenerator < Rails::Generators::Base + def install_bitters + run "bitters install --path ./app/assets/stylesheets" + end + def initialize_active_admin_javascript javascript_asset = 'app/assets/javascripts/active_admin.js.coffee' entries = [ From 29713eabe365e893cdb33fdf3327a512aa5ff660 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 10:38:35 -0400 Subject: [PATCH 06/14] I need to learn how to type :( --- atomic_cms.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atomic_cms.gemspec b/atomic_cms.gemspec index 4e49426..ba711cb 100644 --- a/atomic_cms.gemspec +++ b/atomic_cms.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_dependency 'paperclip', '~> 4.3' s.add_dependency 'bourbon', '~> 4.2.6' s.add_dependency 'neat', '~> 1.7.2' - s.add_dependency 'bitters', '~> 1.10' + s.add_dependency 'bitters', '~> 1.1.0' s.add_development_dependency 'rspec-core', '~> 3.3' s.add_development_dependency 'rspec-expectations', '~> 3.3' From 25f997a2743f7761a479fb65e0ee093b98797014 Mon Sep 17 00:00:00 2001 From: "Jason T. Wong" Date: Fri, 30 Oct 2015 11:09:25 -0400 Subject: [PATCH 07/14] Updated dependencies. Moved require gemfile gems into generators. --- atomic_cms.gemspec | 4 ---- .../atomic_cms/assets/assets_generator.rb | 13 +++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/atomic_cms.gemspec b/atomic_cms.gemspec index ba711cb..572ec7d 100644 --- a/atomic_cms.gemspec +++ b/atomic_cms.gemspec @@ -13,15 +13,11 @@ Gem::Specification.new do |s| s.add_dependency 'rails', '~> 4.2' s.add_dependency 'activeadmin', '1.0.0.pre2' - s.add_dependency 'angularjs-rails', '~> 1.3', '< 1.4' s.add_dependency 'atomic_assets', '~> 0.1.0' s.add_dependency 'jquery-rails', '~> 4.0', '>= 4.0.3' s.add_dependency 'redcarpet', '~> 3.3' s.add_dependency 'slim-rails', '~> 3.0' s.add_dependency 'paperclip', '~> 4.3' - s.add_dependency 'bourbon', '~> 4.2.6' - s.add_dependency 'neat', '~> 1.7.2' - s.add_dependency 'bitters', '~> 1.1.0' s.add_development_dependency 'rspec-core', '~> 3.3' s.add_development_dependency 'rspec-expectations', '~> 3.3' diff --git a/lib/generators/atomic_cms/assets/assets_generator.rb b/lib/generators/atomic_cms/assets/assets_generator.rb index 3336dcb..6f135b9 100644 --- a/lib/generators/atomic_cms/assets/assets_generator.rb +++ b/lib/generators/atomic_cms/assets/assets_generator.rb @@ -1,10 +1,23 @@ module AtomicCms module Generators class AssetsGenerator < Rails::Generators::Base + def install_bourbon + gem 'bourbon', '~> 4.2.6' + end + + def install_neat + gem 'neat', '~> 1.7.2' + end + def install_bitters + gem 'bitters', '~> 1.1.0' run "bitters install --path ./app/assets/stylesheets" end + def install_angular + gem 'angularjs-rails', '~> 1.3', '< 1.4' + end + def initialize_active_admin_javascript javascript_asset = 'app/assets/javascripts/active_admin.js.coffee' entries = [ From 464dd494c655fdafaaf60e02fd43968b74f1902a Mon Sep 17 00:00:00 2001 From: "Jason T. Wong" Date: Fri, 30 Oct 2015 11:19:27 -0400 Subject: [PATCH 08/14] Touched up admin template for scaffolding. --- lib/generators/atomic_cms/templates/admin.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/generators/atomic_cms/templates/admin.rb b/lib/generators/atomic_cms/templates/admin.rb index 9722729..d48d080 100644 --- a/lib/generators/atomic_cms/templates/admin.rb +++ b/lib/generators/atomic_cms/templates/admin.rb @@ -14,7 +14,7 @@ # new form if !f.object.persisted? f.inputs "Details" do - # f.input :title + # f.input :name end f.actions @@ -33,10 +33,9 @@ end column id: "edit-node-column" do - div id: "edit-page" do - f.inputs "Page Details" do - f.input :title - f.input :path + div id: "edit-<%= @scaffold.model_file_name %>" do + f.inputs "<%= @scaffold.model_name %> Details" do + # f.input :name end end From 4b001e0f9e70d1f91e123bdc4ad93d1753dad44b Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 11:32:55 -0400 Subject: [PATCH 09/14] Convert templates to erb --- lib/generators/atomic_cms/scaffold/scaffold_generator.rb | 6 +++--- lib/generators/atomic_cms/templates/{admin.rb => admin.erb} | 0 .../atomic_cms/templates/{controller.rb => controller.erb} | 0 lib/generators/atomic_cms/templates/{model.rb => model.erb} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename lib/generators/atomic_cms/templates/{admin.rb => admin.erb} (100%) rename lib/generators/atomic_cms/templates/{controller.rb => controller.erb} (100%) rename lib/generators/atomic_cms/templates/{model.rb => model.erb} (100%) diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb index a2c0aa1..9667546 100644 --- a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -14,21 +14,21 @@ class ScaffoldGenerator < Rails::Generators::Base def install_model_template setup_scaffold create_template({ - template_name: 'model.rb', + template_name: 'model.erb', full_path: "app/models/#{@scaffold.model_file_name}.rb" }) end def install_controller_template create_template({ - template_name: 'controller.rb', + template_name: 'controller.erb', full_path: "app/controllers/#{@scaffold.controller_file_name}_controller.rb" }) end def install_admin_template create_template({ - template_name: 'admin.rb', + template_name: 'admin.erb', full_path: "app/admin/#{@scaffold.model_file_name}.rb" }) end diff --git a/lib/generators/atomic_cms/templates/admin.rb b/lib/generators/atomic_cms/templates/admin.erb similarity index 100% rename from lib/generators/atomic_cms/templates/admin.rb rename to lib/generators/atomic_cms/templates/admin.erb diff --git a/lib/generators/atomic_cms/templates/controller.rb b/lib/generators/atomic_cms/templates/controller.erb similarity index 100% rename from lib/generators/atomic_cms/templates/controller.rb rename to lib/generators/atomic_cms/templates/controller.erb diff --git a/lib/generators/atomic_cms/templates/model.rb b/lib/generators/atomic_cms/templates/model.erb similarity index 100% rename from lib/generators/atomic_cms/templates/model.rb rename to lib/generators/atomic_cms/templates/model.erb From fa049f8a5bc1fd38dff204ded9b5b917d9b6f444 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 11:45:17 -0400 Subject: [PATCH 10/14] Hound style fixes --- .../atomic_cms/scaffold/scaffold_generator.rb | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb index 9667546..cba1d12 100644 --- a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -1,4 +1,4 @@ -require 'active_support/core_ext/string' +require "active_support/core_ext/string" module AtomicCms module Generators @@ -13,31 +13,31 @@ class ScaffoldGenerator < Rails::Generators::Base def install_model_template setup_scaffold - create_template({ - template_name: 'model.erb', + create_template( + template_name: "model.erb", full_path: "app/models/#{@scaffold.model_file_name}.rb" - }) + ) end def install_controller_template - create_template({ - template_name: 'controller.erb', + create_template( + template_name: "controller.erb", full_path: "app/controllers/#{@scaffold.controller_file_name}_controller.rb" - }) + ) end def install_admin_template - create_template({ - template_name: 'admin.erb', + create_template( + template_name: "admin.erb", full_path: "app/admin/#{@scaffold.model_file_name}.rb" - }) + ) end def install_show_view_template - create_template({ - template_name: 'show.html.slim', + create_template( + template_name: "show.html.slim", full_path: "app/views/#{@scaffold.view_folder}/show.html.slim" - }) + ) end def create_migration @@ -61,7 +61,7 @@ def setup_scaffold end def create_template(options) - template( options[:template_name], options[:full_path] ) + template(options[:template_name], options[:full_path]) end end end From 3b1f3a295702c42ddeac3ed700c02273dec83ac4 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 11:48:13 -0400 Subject: [PATCH 11/14] Hound regex --- lib/generators/atomic_cms/scaffold/scaffold_generator.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb index cba1d12..c46d598 100644 --- a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -45,7 +45,9 @@ def create_migration end def set_route - inject_into_file "config/routes.rb", "\n resources :#{@scaffold.controller_file_name}\n", after: /\/atomic_cms"/ + inject_into_file "config/routes.rb", + "\n resources :#{@scaffold.controller_file_name}\n", + after: %r{/atomic_cms"} end private From eb9378908b1db330c4bf509b2bb2254b8a08ccc2 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 11:54:30 -0400 Subject: [PATCH 12/14] more hound --- .../atomic_cms/assets/assets_generator.rb | 22 +++++++++---------- .../atomic_cms/scaffold/scaffold_generator.rb | 4 +++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/generators/atomic_cms/assets/assets_generator.rb b/lib/generators/atomic_cms/assets/assets_generator.rb index 6f135b9..097a52b 100644 --- a/lib/generators/atomic_cms/assets/assets_generator.rb +++ b/lib/generators/atomic_cms/assets/assets_generator.rb @@ -2,41 +2,41 @@ module AtomicCms module Generators class AssetsGenerator < Rails::Generators::Base def install_bourbon - gem 'bourbon', '~> 4.2.6' + gem "bourbon", "~> 4.2.6" end def install_neat - gem 'neat', '~> 1.7.2' + gem "neat", "~> 1.7.2" end def install_bitters - gem 'bitters', '~> 1.1.0' + gem "bitters", "~> 1.1.0" run "bitters install --path ./app/assets/stylesheets" end def install_angular - gem 'angularjs-rails', '~> 1.3', '< 1.4' + gem "angularjs-rails", "~> 1.3", "< 1.4" end def initialize_active_admin_javascript - javascript_asset = 'app/assets/javascripts/active_admin.js.coffee' + javascript_asset = "app/assets/javascripts/active_admin.js.coffee" entries = [ - '#= require angular', - '#= require angular-sanitize', - '#= require atomic_cms' + "#= require angular", + "#= require angular-sanitize", + "#= require atomic_cms" ] append_to_file( asset_file: javascript_asset, entries: entries ) end def initialize_active_admin_scss - scss_asset = 'app/assets/stylesheets/active_admin.scss' + scss_asset = "app/assets/stylesheets/active_admin.scss" entries = [ '@import "bourbon";', '@import "neat";', '@import "base/variables";', '@import "base/grid-settings";', '@import "atomic_cms";', - '', + '", '#component_preview {', ' @import "base/buttons";', ' @import "base/forms";', @@ -54,7 +54,7 @@ def initialize_active_admin_scss private def append_to_file(options) - open(options[:asset_file], 'a') do |asset_file| + open(options[:asset_file], "a") do |asset_file| options[:entries].each do |entry| asset_file.puts entry end diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb index c46d598..8e1c59e 100644 --- a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -45,9 +45,11 @@ def create_migration end def set_route - inject_into_file "config/routes.rb", + inject_into_file( + "config/routes.rb", "\n resources :#{@scaffold.controller_file_name}\n", after: %r{/atomic_cms"} + ) end private From bfd23f10f30564e7c8446b014f493c91b0bad973 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 12:00:55 -0400 Subject: [PATCH 13/14] even more hound --- lib/generators/atomic_cms/assets/assets_generator.rb | 2 +- lib/generators/atomic_cms/scaffold/scaffold_generator.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/generators/atomic_cms/assets/assets_generator.rb b/lib/generators/atomic_cms/assets/assets_generator.rb index 097a52b..a9008d1 100644 --- a/lib/generators/atomic_cms/assets/assets_generator.rb +++ b/lib/generators/atomic_cms/assets/assets_generator.rb @@ -36,7 +36,7 @@ def initialize_active_admin_scss '@import "base/variables";', '@import "base/grid-settings";', '@import "atomic_cms";', - '", + '', '#component_preview {', ' @import "base/buttons";', ' @import "base/forms";', diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb index 8e1c59e..419564e 100644 --- a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -22,7 +22,7 @@ def install_model_template def install_controller_template create_template( template_name: "controller.erb", - full_path: "app/controllers/#{@scaffold.controller_file_name}_controller.rb" + full_path: controller_template_name ) end @@ -67,6 +67,10 @@ def setup_scaffold def create_template(options) template(options[:template_name], options[:full_path]) end + + def controller_template_name + "app/controllers/#{@scaffold.controller_file_name}_controller.rb" + end end end end From 32c192c4f2f0d609916f4d93883aefd8022b7918 Mon Sep 17 00:00:00 2001 From: Sam McDavid Date: Fri, 30 Oct 2015 12:02:08 -0400 Subject: [PATCH 14/14] hound indentation --- lib/generators/atomic_cms/scaffold/scaffold_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb index 419564e..41bcf36 100644 --- a/lib/generators/atomic_cms/scaffold/scaffold_generator.rb +++ b/lib/generators/atomic_cms/scaffold/scaffold_generator.rb @@ -69,7 +69,7 @@ def create_template(options) end def controller_template_name - "app/controllers/#{@scaffold.controller_file_name}_controller.rb" + "app/controllers/#{@scaffold.controller_file_name}_controller.rb" end end end