cambium 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/cambium.gemspec +25 -23
  3. data/lib/cambium/version.rb +1 -1
  4. data/lib/generators/cambium/helpers/_autoloader.rb +12 -0
  5. data/lib/generators/cambium/helpers/dependencies_helper.rb +58 -0
  6. data/lib/generators/cambium/helpers/generators_helper.rb +227 -0
  7. data/lib/generators/cambium/install/admin_generator.rb +68 -74
  8. data/lib/generators/cambium/install/app_generator.rb +86 -95
  9. data/lib/generators/cambium/install/config_generator.rb +98 -108
  10. data/lib/generators/cambium/install/utilities_generator.rb +2 -50
  11. data/lib/generators/cambium/model/image_generator.rb +67 -0
  12. data/lib/generators/cambium/model/page_generator.rb +131 -0
  13. data/lib/generators/cambium/model/post_generator.rb +71 -0
  14. data/lib/generators/cambium/model/tag_generator.rb +40 -0
  15. data/lib/generators/cambium/model/user_generator.rb +78 -0
  16. data/lib/generators/cambium/templates/Gemfile +43 -0
  17. data/lib/generators/cambium/templates/_partials/pages/admin_icon.rb +6 -0
  18. data/lib/generators/cambium/templates/app/assets/javascripts/admin/admin.js.coffee +3 -1
  19. data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/image.js.coffee +14 -0
  20. data/lib/generators/cambium/templates/app/assets/javascripts/admin/models/tag.js.coffee +14 -0
  21. data/lib/generators/cambium/templates/app/assets/javascripts/admin/parser_rules/custom.js +552 -0
  22. data/lib/generators/cambium/templates/app/assets/javascripts/admin/routers/router.js.coffee +21 -0
  23. data/lib/generators/cambium/templates/app/assets/javascripts/admin/tag.jst.ejs +7 -0
  24. data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/image.jst.ejs +3 -0
  25. data/lib/generators/cambium/templates/app/assets/javascripts/admin/templates/post_tag.jst.ejs +1 -0
  26. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/image_upload.js.coffee +28 -0
  27. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/tags.js.coffee +158 -0
  28. data/lib/generators/cambium/templates/app/assets/javascripts/admin/views/wysiwyg.js.coffee +77 -0
  29. data/lib/generators/cambium/templates/app/controllers/admin/images_controller.rb +45 -0
  30. data/lib/generators/cambium/templates/app/controllers/admin/pages_controller.rb +42 -0
  31. data/lib/generators/cambium/templates/app/controllers/admin/posts_controller.rb +39 -0
  32. data/lib/generators/cambium/templates/app/controllers/admin/taggings_controller.rb +69 -0
  33. data/lib/generators/cambium/templates/app/controllers/admin/tags_controller.rb +11 -0
  34. data/lib/generators/cambium/templates/app/controllers/admin_controller.rb +11 -2
  35. data/lib/generators/cambium/templates/app/controllers/application_controller.rb +2 -2
  36. data/lib/generators/cambium/templates/app/controllers/images_controller.rb +45 -0
  37. data/lib/generators/cambium/templates/app/controllers/pages_controller.rb +12 -0
  38. data/lib/generators/cambium/templates/app/controllers/posts_controller.rb +11 -0
  39. data/lib/generators/cambium/templates/app/helpers/admin/pages_controller.rb +47 -0
  40. data/lib/generators/cambium/templates/app/helpers/admin_helper.rb +1 -1
  41. data/lib/generators/cambium/templates/app/models/concerns/image_cropper.rb +24 -0
  42. data/lib/generators/cambium/templates/app/models/concerns/publishable.rb +32 -4
  43. data/lib/generators/cambium/templates/app/models/concerns/slug.rb +4 -0
  44. data/lib/generators/cambium/templates/app/models/concerns/tags.rb +6 -1
  45. data/lib/generators/cambium/templates/app/models/image.rb +43 -0
  46. data/lib/generators/cambium/templates/app/models/page.rb +81 -0
  47. data/lib/generators/cambium/templates/app/models/post.rb +45 -0
  48. data/lib/generators/cambium/templates/app/models/tag.rb +33 -0
  49. data/lib/generators/cambium/templates/app/models/tagging.rb +20 -0
  50. data/lib/generators/cambium/templates/app/uploaders/image_uploader.rb +91 -0
  51. data/lib/generators/cambium/templates/app/views/admin/images/_image.html.erb +1 -0
  52. data/lib/generators/cambium/templates/app/views/admin/images/create.js.erb +7 -0
  53. data/lib/generators/cambium/templates/app/views/admin/images/index.json.jbuilder +4 -0
  54. data/lib/generators/cambium/templates/app/views/admin/pages/_form.html.erb +26 -0
  55. data/lib/generators/cambium/templates/app/views/admin/posts/_form.html.erb +40 -0
  56. data/lib/generators/cambium/templates/app/views/admin/shared/_insert_image.html.erb +12 -0
  57. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_editor.html.erb +3 -3
  58. data/lib/generators/cambium/templates/app/views/admin/shared/forms/_form_page.html.erb +5 -1
  59. data/lib/generators/cambium/templates/app/views/home/index.html.erb +7 -0
  60. data/lib/generators/cambium/templates/app/views/page_templates/default.html.erb +2 -0
  61. data/lib/generators/cambium/templates/app/views/posts/_post.html.erb +4 -0
  62. data/lib/generators/cambium/templates/app/views/posts/index.html.erb +1 -0
  63. data/lib/generators/cambium/templates/app/views/posts/show.html.erb +10 -0
  64. data/lib/generators/cambium/templates/config/app_routes.rb +77 -0
  65. data/lib/generators/cambium/templates/config/routes.rb.erb +11 -2
  66. data/lib/generators/cambium/templates/db/migrate/create_pages.rb.erb +24 -0
  67. data/lib/generators/cambium/templates/db/migrate/create_posts.rb +19 -0
  68. data/lib/generators/cambium/templates/gitignore +1 -0
  69. metadata +52 -256
  70. data/lib/generators/cambium/install/users_generator.rb +0 -104
  71. data/lib/generators/cambium/templates/app/assets/stylesheets/admin/partials/_icons.scss +0 -5194
@@ -0,0 +1,131 @@
1
+ require 'rake'
2
+ require 'rails/generators'
3
+ require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
4
+
5
+ module Cambium
6
+ module Model
7
+ class PageGenerator < Rails::Generators::Base
8
+ desc "Add pages to your project"
9
+
10
+ source_root File.expand_path('../../templates', __FILE__)
11
+
12
+ # Since we're using images, we need to make sure the image generator has
13
+ # already been run. And, like all other models, we want to make sure we
14
+ # already have an admin available to us.
15
+ #
16
+ def set_dependencies
17
+ check_dependencies(['cambium:install:admin','cambium:model:image'])
18
+ end
19
+
20
+ # We need a couple concerns, so we add them here unless they are already
21
+ # part of the project.
22
+ #
23
+ def add_concerns
24
+ add_model_concerns(['publishable', 'slug'])
25
+ end
26
+
27
+ # Add our model file.
28
+ #
29
+ def add_model_files
30
+ template("app/models/page.rb", "app/models/page.rb")
31
+ end
32
+
33
+ # Since we have to customize the up/down methods in the migration, we
34
+ # don't generate the model, we just copy an interpreted template.
35
+ #
36
+ def add_migration_files
37
+ template(
38
+ "db/migrate/create_pages.rb.erb",
39
+ "db/migrate/#{timestamp}_create_pages.rb"
40
+ )
41
+ migrate_and_annotate
42
+ end
43
+
44
+ # We are setting a global template directory for reference throughout the
45
+ # project.
46
+ #
47
+ def add_application_config
48
+ application 'config.template_directory = "#{Rails.root}/app/views/page_templates"'
49
+ end
50
+
51
+ # We add our page templates directory and our default template.
52
+ #
53
+ def add_page_templates
54
+ directory('app/views/page_templates','app/views/page_templates')
55
+ end
56
+
57
+ # We have two controllers here -- one for the app and one for the admin.
58
+ # We'll add them both instead of generating them since they are
59
+ # customized.
60
+ #
61
+ def add_controller_files
62
+ template("app/controllers/pages_controller.rb",
63
+ "app/controllers/pages_controller.rb")
64
+ template("app/controllers/admin/pages_controller.rb",
65
+ "app/controllers/admin/pages_controller.rb")
66
+ end
67
+
68
+ # We add the customized views that override the default admin views, while
69
+ # the app views are driven by the page template
70
+ #
71
+ def add_admin_views
72
+ directory("app/views/admin/pages", "app/views/admin/pages")
73
+ end
74
+
75
+ # We need to add routes to routes file for the app and the admin. We
76
+ # expect to see an admin, so we don't have a check, but we do need the
77
+ # public route. Since the contents of the routes file are variable, we
78
+ # have a check and notify the user if we can't find what we need.
79
+ #
80
+ def add_routes
81
+ # App
82
+ insert_into_file(
83
+ "config/routes.rb",
84
+ "get '/:slug', :to => 'pages#show', :as => 'page'\n\n ",
85
+ :before => /root\ (.*)\n/
86
+ )
87
+ if File.read(Rails.root.join('config','routes.rb')).include?('/:slug')
88
+ uncomment_lines(
89
+ Rails.root.join('config','routes.rb'),
90
+ /get\ \'\/\:slug/
91
+ )
92
+ else
93
+ add_routes_manually
94
+ end
95
+ # Admin
96
+ insert_into_file(
97
+ "config/routes.rb",
98
+ " resources :pages, :except => [:show]\n",
99
+ :after => /namespace\ \:admin(.*)\n/
100
+ )
101
+ end
102
+
103
+ # In the admin helper, we can add a link and an icon to the sidebar. The
104
+ # easiest way to do this is to add it to the top. The user can move if
105
+ # they'd like.
106
+ #
107
+ def add_admin_icon
108
+ insert_into_file(
109
+ "app/helpers/admin_helper.rb",
110
+ file_contents('_partials/pages/admin_icon.rb'),
111
+ :after => /items\ \=\ \[\n/
112
+ )
113
+ end
114
+
115
+ private
116
+
117
+ # If we couldn't find a root route in the config file, then we tell the
118
+ # user to add the routes manually.
119
+ #
120
+ def add_routes_manually
121
+ say set_color(
122
+ "\nAdd the following to the end of your config/routes.rb file:\n",
123
+ :yellow,
124
+ :bold
125
+ )
126
+ say " get '/:slug', :to => 'pages#show', :as => 'page'\n"
127
+ end
128
+
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,71 @@
1
+ require 'rake'
2
+ require 'rails/generators'
3
+ require "#{Gem::Specification.find_by_name("cambium").gem_dir}/lib/generators/cambium/helpers/generators_helper.rb"
4
+ include Cambium::GeneratorsHelper
5
+
6
+ module Cambium
7
+ module Model
8
+ class PostGenerator < Rails::Generators::Base
9
+ desc "Add blog posts to your project"
10
+
11
+ # ------------------------------------------ Class Methods
12
+
13
+ source_root File.expand_path('../../templates', __FILE__)
14
+
15
+ # ------------------------------------------ Model Concern
16
+
17
+ def add_model_concerns
18
+ copy_file "app/models/concerns/publishable.rb", "app/models/concerns/publishable.rb"
19
+ copy_file "app/models/concerns/slug.rb", "app/models/concerns/slug.rb"
20
+ copy_file "app/models/concerns/tags.rb", "app/models/concerns/tags.rb"
21
+ end
22
+
23
+ # ------------------------------------------ Add Model Templates
24
+
25
+ def add_model_files
26
+ model_path = "app/models/post.rb"
27
+ template(model_path, model_path)
28
+ end
29
+
30
+ # ------------------------------------------ Add Migration Templates
31
+
32
+ def add_migration_files
33
+ template(
34
+ 'db/migrate/create_posts.rb',
35
+ "db/migrate/#{timestamp}_create_posts.rb"
36
+ )
37
+ end
38
+
39
+ # ------------------------------------------ Add Controller Templates
40
+
41
+ def add_controller_files
42
+ controller_path = "app/controllers/posts_controller.rb"
43
+ template(controller_path, controller_path)
44
+ end
45
+
46
+ # ------------------------------------------ Add View Templates
47
+
48
+ def add_view_files
49
+ view_path = "app/views/posts"
50
+ directory(view_path, view_path)
51
+ end
52
+
53
+ # ------------------------------------------ Migrate & Annotate
54
+
55
+ def migrate_and_annotate
56
+ rake "db:migrate"
57
+ run_cmd "#{be} annotate"
58
+ end
59
+
60
+ # ------------------------------------------ User output
61
+ # This is kind of a cop out in leu of appending to the *end* of routes.rb
62
+ def notes_to_user
63
+ puts "\n== Don't forget to add routes for blog posts ================="
64
+ puts "get '/news', :to => 'posts#index', :as => 'posts'"
65
+ puts "get '/news/:slug', :to => 'posts#show', :as => 'post'"
66
+ puts "\n"
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,40 @@
1
+ require 'rake'
2
+ require 'rails/generators'
3
+ require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
4
+
5
+ module Cambium
6
+ module Model
7
+ class TagGenerator < Rails::Generators::Base
8
+ desc "Add tags to your project"
9
+
10
+ source_root File.expand_path('../../templates', __FILE__)
11
+
12
+ # Make sure the tags concern is in the project. If not, add it!
13
+ #
14
+ def add_concerns
15
+ add_model_concerns(['tags'])
16
+ end
17
+
18
+ # Since the models are simple enough, we can generate from the command
19
+ # line.
20
+ #
21
+ def generate_models
22
+ generate "model Tag name ci_name slug"
23
+ generate "model Tagging tag_id:integer taggable_id:integer taggable_type"
24
+ end
25
+
26
+ # Add our customized model files.
27
+ #
28
+ def add_model_files
29
+ ['tag','tagging'].each do |file|
30
+ template("app/models/#{file}.rb", "app/models/#{file}.rb")
31
+ end
32
+ end
33
+
34
+ def finish_up
35
+ migrate_and_annotate
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,78 @@
1
+ require 'rake'
2
+ require 'rails/generators'
3
+ require File.expand_path('../../helpers/_autoloader.rb', __FILE__)
4
+
5
+ module Cambium
6
+ module Model
7
+ class UserGenerator < Rails::Generators::Base
8
+ desc "Setup users model for new rails project"
9
+
10
+ source_root File.expand_path('../../templates', __FILE__)
11
+
12
+ # We'll begin by installing the gems we need to work the user model
13
+ #
14
+ def add_user_gems
15
+ @user_gems = ['devise','annotate']
16
+ install_gems @user_gems
17
+ bundle
18
+ end
19
+
20
+ # Install Devise
21
+ #
22
+ def install_devise
23
+ unless File.exist?("#{Rails.root}/config/initializers/devise.rb")
24
+ generate "devise:install"
25
+ end
26
+ unless File.exist?("#{Rails.root}/app/models/user.rb")
27
+ generate "devise User"
28
+ end
29
+ end
30
+
31
+ # Inject the is_admin column into the migration file if user plans on
32
+ # using the admin module.
33
+ #
34
+ def add_admin_column_to_users
35
+ @admin = false
36
+ if yes? "Would you like to add admin authentication to User model?"
37
+ @admin = true
38
+ file = Dir.glob("#{Rails.root}/db/migrate/*devise_create_users.rb").first
39
+ insert_into_file(
40
+ file,
41
+ "## Admin\n t.boolean :is_admin, :default => false \n\n ",
42
+ :before => "t.timestamps"
43
+ )
44
+ end
45
+ end
46
+
47
+ # Add our customized User model file
48
+ #
49
+ def add_user_model_file
50
+ copy_file "app/models/user.rb", "app/models/user.rb", :force => true
51
+ end
52
+
53
+ # Create model from migration
54
+ #
55
+ def migrate_and_annotate
56
+ rake "db:migrate"
57
+ run_cmd "#{be} annotate"
58
+ end
59
+
60
+ # Add the default login/logout redirects
61
+ #
62
+ def add_application_controller_redirects
63
+ insert_into_file(
64
+ "app/controllers/application_controller.rb",
65
+ template_snippet("app/controllers/application_controller.rb"),
66
+ :after => ":exception"
67
+ )
68
+ end
69
+
70
+ # Let the user know the gems we installed
71
+ #
72
+ def finish_up
73
+ gem_installation_notification(@user_gems)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,43 @@
1
+
2
+
3
+ # ------------------------------------------ Base
4
+
5
+ gem 'unicorn-rails'
6
+
7
+ # ------------------------------------------ Assets
8
+
9
+ gem 'sass-rails'
10
+ gem 'uglifier'
11
+ gem 'coffee-rails'
12
+ gem 'jquery-rails'
13
+ gem 'bones-rails'
14
+ gem 'bourbon'
15
+ gem 'backbone-on-rails'
16
+ gem "jquery-fileupload-rails"
17
+
18
+ # ------------------------------------------ View Helpers
19
+
20
+ gem 'jbuilder'
21
+ gem 'simple_form'
22
+ gem 'wysihtml5-rails'
23
+ gem 'pickadate-rails'
24
+
25
+ # ------------------------------------------ Utilities
26
+
27
+ gem 'ancestry'
28
+ gem 'kaminari'
29
+ gem 'cambium'
30
+ gem 'devise'
31
+ gem 'carrierwave'
32
+ gem 'hirb'
33
+
34
+ # ------------------------------------------ Development/Test
35
+
36
+ group :development do
37
+ gem 'annotate'
38
+ end
39
+
40
+ gem 'factory_girl_rails'
41
+ gem 'faker'
42
+
43
+ # ------------------------------------------ User Gems
@@ -0,0 +1,6 @@
1
+ {
2
+ :label => 'Pages',
3
+ :icon => 'file3',
4
+ :path => admin_pages_path,
5
+ :controllers => ['pages']
6
+ },
@@ -1,10 +1,12 @@
1
1
  #= require jquery
2
2
  #= require jquery_ujs
3
+ #= require jquery-fileupload/basic
4
+ #= require jquery-fileupload/vendor/tmpl
3
5
  #= require pickadate/picker
4
6
  #= require pickadate/picker.date
5
7
  #= require pickadate/picker.time
6
8
  #= require admin/wysihtml5
7
- #= require parser_rules/advanced
9
+ #= require admin/parser_rules/custom
8
10
  #= require underscore
9
11
  #= require backbone
10
12
  #= require_self
@@ -0,0 +1,14 @@
1
+ class Admin.Models.Image extends Backbone.Model
2
+
3
+ urlRoot: "/admin/json/images"
4
+
5
+ class Admin.Collections.Images extends Backbone.Collection
6
+
7
+ model: Admin.Models.Image
8
+
9
+ initialize: (url) =>
10
+ @url = url
11
+
12
+ # comparator: (image) ->
13
+ # if image.get("sort")
14
+ # return image.get("sort")
@@ -0,0 +1,14 @@
1
+ class Admin.Models.Tag extends Backbone.Model
2
+
3
+ urlRoot: "/admin/json/taggings"
4
+
5
+ class Admin.Collections.Tags extends Backbone.Collection
6
+
7
+ model: Admin.Models.Tag
8
+
9
+ initialize: (url) =>
10
+ @url = url
11
+
12
+ comparator: (tag) ->
13
+ if tag.get("title")
14
+ return tag.get("title").toLowerCase()