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,158 @@
1
+ class Admin.Views.Tags extends Backbone.View
2
+
3
+ el: "#tag-container"
4
+
5
+ dup: false
6
+ active: 0
7
+
8
+ template: JST['admin/templates/tag']
9
+
10
+ events:
11
+ "keyup #new-tag-title": "keyController"
12
+ "keydown #new-tag-title": "checkEnter"
13
+ "click .delete-tag": "deleteTag"
14
+ "click a.autocomplete": "addAutocomplete"
15
+
16
+ # ------------------------------------------- init
17
+
18
+ initialize : (options) =>
19
+ @setOptions options
20
+ @collection = new Admin.Collections.Tags @url
21
+ @fetchTags()
22
+ $('body').click (e) =>
23
+ unless $(e.target).hasClass('deleteTag') or $(e.target).hasClass('autocomplete') or $(e.target).hasClass('new-tag-title')
24
+ $('ul.autocomplete').html ""
25
+
26
+ setOptions: (options) =>
27
+ if options.id
28
+ @url = options.url
29
+ @taggable = options.taggable
30
+ @taggable_id = options.id
31
+
32
+ # ------------------------------------------- get data
33
+
34
+ fetchTags: =>
35
+ @collection.fetch
36
+ success: (tags) =>
37
+ @tags = tags.toJSON()
38
+ @renderTags()
39
+ @getAllTags()
40
+
41
+ getAllTags: =>
42
+ $.ajax
43
+ url: "/admin/json/tags"
44
+ success: (data) =>
45
+ @allTags = new Array()
46
+ @currentTags = new Array()
47
+ @currentTags.push($(tag).html()) for tag in $('#tag-list li > span.title')
48
+ for tag in data
49
+ @allTags.push tag.name if @currentTags.indexOf(tag.name) is -1
50
+
51
+ # ------------------------------------------- render
52
+
53
+ renderTags: =>
54
+ $(".loading").html ""
55
+ $("#tag-list").html ""
56
+ _.each @tags, (tag) =>
57
+ @renderTag(tag) if `tag.title != undefined`
58
+
59
+ renderTag: (tag) =>
60
+ $('#tag-list').append @template
61
+ id: tag.id
62
+ tag_id: tag.tag_id
63
+ title: tag.title
64
+
65
+ # ------------------------------------------- events controller
66
+
67
+ keyController: (e) =>
68
+ e.preventDefault()
69
+ title = $(e.target).val()
70
+ if title == ""
71
+ @reset()
72
+ else
73
+ switch e.keyCode
74
+ # when 13 then @checkDuplicates(title) # Enter
75
+ when 38 # Up Arrow
76
+ if @active != 0
77
+ @active--
78
+ if @active == 0
79
+ $("#new-tag-title").val @origVal
80
+ else
81
+ @updateVal(title)
82
+ when 40 # Down Arrow
83
+ @origVal = title if @active == 0
84
+ @active++ if @active != @maxAutocomplete
85
+ @updateVal(title)
86
+ else
87
+ @autocomplete(title)
88
+
89
+ checkEnter: (e) =>
90
+ $('div.tagging-errors').html ""
91
+ if e.keyCode == 13
92
+ e.preventDefault()
93
+ @splitTitle( $(e.target).val() )
94
+ # @checkDuplicates( $(e.target).val() )
95
+
96
+ # ------------------------------------------- autocomplete
97
+
98
+ updateVal: (title) =>
99
+ $('ul.autocomplete li').removeClass "active"
100
+ $("li#arrow-#{@active}").addClass "active"
101
+ $("#new-tag-title").val( $("#arrow-#{@active} > a").html() )
102
+
103
+ reset: =>
104
+ @active = 0
105
+ $('#new-tag-title').val ""
106
+ $('ul.autocomplete').html ""
107
+
108
+ autocomplete: (title) =>
109
+ $('ul.autocomplete').html ""
110
+ if `title != ""`
111
+ arrow = 1
112
+ console.log @allTags
113
+ for tag in @allTags
114
+ if tag.toLowerCase().indexOf(title.toLowerCase()) > -1
115
+ $('ul.autocomplete').append "<li id=\"arrow-#{arrow}\"><a class=\"autocomplete\" href=\"#\">#{tag}</a></li>"
116
+ arrow++
117
+ @maxAutocomplete = arrow - 1
118
+
119
+ addAutocomplete: (e) =>
120
+ e.preventDefault()
121
+ title = $(e.target).html()
122
+ @newTag(title)
123
+ $('ul.autocomplete').html ""
124
+
125
+ splitTitle: (str) =>
126
+ titles = str.split(', ')
127
+ for t in titles
128
+ @checkDuplicates(t)
129
+
130
+ checkDuplicates: (title) =>
131
+ for li in $('#tag-list li')
132
+ @dup = true if title.toLowerCase() == $(li).data("title").toLowerCase()
133
+ if @dup is true
134
+ $('div.tagging-errors').append "You already have the tag: #{title}<br>"
135
+ # @reset()
136
+ @dup = false
137
+ else if `title != ""`
138
+ @newTag(title)
139
+
140
+ # ------------------------------------------- CRUD
141
+
142
+ newTag: (title) =>
143
+ model = new Admin.Models.Tag
144
+ tag_title: title
145
+ taggable: @taggable
146
+ taggable_id: @taggable_id
147
+ model.save null,
148
+ complete: (model, response) =>
149
+ @fetchTags()
150
+ @reset()
151
+
152
+ deleteTag: (e) =>
153
+ e.preventDefault()
154
+ id = $(e.target).parents('li').data('id')
155
+ model = @collection.get(id)
156
+ model.destroy()
157
+ $(e.target).parents('li').next('.separator').remove()
158
+ $(e.target).parents('li').remove()
@@ -2,9 +2,86 @@ class Admin.Views.Wysiwyg extends Backbone.View
2
2
 
3
3
  el: 'body'
4
4
  textarea: '.wysiwyg'
5
+ modal: '#wysihtml5-insert-image-modal'
6
+ imagesContainer: 'div.images-container'
7
+
8
+ imageTemplate: JST['admin/templates/image']
9
+
10
+ events:
11
+ 'click a.browse-images': 'initInsertImage'
5
12
 
6
13
  initialize: (options) =>
14
+ @initEditor(options)
15
+ options.image_upload = true if typeof(options.image_upload) == undefined
16
+ if options.image_upload == true
17
+ @renderInsertImageModal()
18
+ @collection = new Admin.Collections.Images options.url
19
+ @fetchImages()
20
+ @initImageUpload()
21
+ else
22
+ $('a.browse-images').hide()
23
+
24
+ initEditor: (options) =>
7
25
  editor = new wysihtml5.Editor options.id, #textarea-id
8
26
  toolbar: options.toolbarID # id of toolbar element
9
27
  parserRules: wysihtml5ParserRules # defined in parser rules set
10
28
  stylesheets: [ WYSIWYG_BASE_STYLES, WYSIWYG_CUSTOM_STYLES ] # defined in admin.html.erb
29
+
30
+ fetchImages: =>
31
+ @collection.fetch
32
+ success: (images) =>
33
+ @images = images.toJSON()
34
+ @renderImages()
35
+ $("#{@imagesContainer} img").click (e) =>
36
+ $('input.insert-image').val window.location.origin+$(e.target).data('src')
37
+ @closeModal()
38
+
39
+ renderImages: =>
40
+ $(@imagesContainer).html ""
41
+ if @images.length > 0
42
+ _.each @images, (image) =>
43
+ if image.filename
44
+ $(@imagesContainer).append @imageTemplate(image: image)
45
+
46
+ renderInsertImageModal: =>
47
+ $(window).resize(@positionInsertImageModal)
48
+ $("#{@modal} .modal a.close").click @closeModal
49
+
50
+ closeModal: =>
51
+ $(@modal).hide()
52
+ $(@el).css
53
+ overflow: 'auto'
54
+ height: 'auto'
55
+
56
+ initInsertImage: (e) =>
57
+ $(@el).css
58
+ overflow: 'hidden'
59
+ height: '100%'
60
+ @fetchImages()
61
+ @positionInsertImageModal()
62
+ $(@modal).show()
63
+
64
+ positionInsertImageModal: =>
65
+ ww = $(window).width()
66
+ wh = $(window).height()
67
+ left = ( ww / 2 ) - 331
68
+ top = ( wh / 2 ) - 200
69
+ $("#{@modal} .modal").css
70
+ top: "#{top}px"
71
+ left: "#{left}px"
72
+
73
+ initImageUpload: =>
74
+ $("#image_filename").attr "name", "image[filename]"
75
+ $("#new_image").fileupload
76
+ add: (e,data) ->
77
+ $(".images-container").prepend """
78
+ <div class="loading">Uploading #{data.files[0].name}...</div>
79
+ """
80
+ data.submit()
81
+ complete: (e,data) =>
82
+ @fetchImages()
83
+ $(".images-container div.loading").first().remove()
84
+ # $(".images-container div.loading").insertBefore( $(".images-container img").first() )
85
+ $(".images-container img").click (e) =>
86
+ $('input.insert-image').val $(e.target).data('src')
87
+ @closeModal()
@@ -0,0 +1,45 @@
1
+ class Admin::ImagesController < ApplicationController
2
+
3
+ def index
4
+ @images = Image.all
5
+ respond_to do |format|
6
+ format.json { render :json => @images }
7
+ end
8
+ end
9
+
10
+ def edit
11
+ @url = @show
12
+ @image = Image.find(params[:id])
13
+ end
14
+
15
+ def create
16
+ @image = Image.new(create_params)
17
+ @image.save
18
+ end
19
+
20
+ def update
21
+ if @image.update_attributes(create_params)
22
+ redirect_to @project_edit, notice: 'Image was successfully updated.'
23
+ else
24
+ render action: "edit"
25
+ end
26
+ end
27
+
28
+ def destroy
29
+ @image = Image.find(params[:id])
30
+ @image.destroy
31
+ respond_to do |format|
32
+ format.json { render :nothing => true }
33
+ end
34
+ end
35
+
36
+
37
+ private
38
+
39
+ def create_params
40
+ params.require(:image).permit(
41
+ :filename, :crop_x, :crop_y, :crop_w, :crop_h
42
+ )
43
+ end
44
+
45
+ end
@@ -0,0 +1,42 @@
1
+ class Admin::PagesController < AdminController
2
+
3
+ def index
4
+ @items = @model.all.unscoped.order(:title)
5
+ end
6
+
7
+ def new
8
+ @image = Image.new
9
+ @image_url = admin_images_path(@image)
10
+ super
11
+ end
12
+
13
+ def edit
14
+ @image = Image.new
15
+ @image_url = admin_images_path(@image)
16
+ super
17
+ end
18
+
19
+ def update
20
+ update_params ||= create_params
21
+ if @item.update(update_params)
22
+ @item.update_column(:slug, @item.create_slug)
23
+ redirect_to edit_admin_page_path(@item), :notice => "#{@model.to_s} was updated successfully."
24
+ else
25
+ render :action => "edit"
26
+ end
27
+ end
28
+
29
+
30
+ private
31
+ def set_defaults
32
+ super
33
+ @model = Page
34
+ end
35
+
36
+ def create_params
37
+ params.require(:page).permit(:title, :body, :slug, :position, :template,
38
+ :description, :active_date, :active_time, :inactive_date, :in_top_nav,
39
+ :inactive_time, :parent_id)
40
+ end
41
+
42
+ end
@@ -0,0 +1,39 @@
1
+ class Admin::PostsController < AdminController
2
+
3
+ def new
4
+ @image = Image.new
5
+ @image_url = admin_images_path(@image)
6
+ super
7
+ @item.user = current_user
8
+ end
9
+
10
+ def edit
11
+ @image = Image.new
12
+ @image_url = admin_images_path(@image)
13
+ super
14
+ end
15
+
16
+ private
17
+ def set_defaults
18
+ super
19
+ @model = Post
20
+ end
21
+
22
+ def create_params
23
+ params.require(:post).permit(
24
+ :title,
25
+ :body,
26
+ :slug,
27
+ :active_date,
28
+ :active_time,
29
+ :inactive_date,
30
+ :inactive_time,
31
+ :main_image,
32
+ :remove_main_image,
33
+ :is_featured,
34
+ :user_id,
35
+ :tag_list
36
+ )
37
+ end
38
+
39
+ end
@@ -0,0 +1,69 @@
1
+ class Admin::TaggingsController < ApplicationController
2
+ before_filter :get_params
3
+
4
+ def index
5
+ respond_to do |format|
6
+ format.json # { render json: @taggings }
7
+ end
8
+ end
9
+
10
+ def edit
11
+ end
12
+
13
+ def create
14
+ tags = Tag.where("lower(name) = ?", params[:tag_title].downcase)
15
+ if tags.count > 0
16
+ @tag = tags.first
17
+ else
18
+ @tag = Tag.create(name: params[:tag_title])
19
+ end
20
+
21
+ @taggable = params[:taggable].constantize.find(params[:taggable_id])
22
+ logger.debug @taggable.inspect
23
+ Tagging.where(tag_id: @tag.id, taggable_type: @taggable.class.name, taggable_id: @taggable.id).first_or_create
24
+ render nothing: true
25
+ end
26
+
27
+ def update
28
+ respond_to do |format|
29
+ if @tagging.update_attributes(params[:tagging])
30
+ format.json { head :no_content }
31
+ else
32
+ format.json { render json: @tagging.errors, status: :unprocessable_entity }
33
+ end
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ @tagging = Tagging.find(params[:id])
39
+ @tagging.destroy
40
+ render :nothing => true
41
+ end
42
+
43
+ private
44
+ def get_params
45
+ if params[:page_id]
46
+ @page = Page.find(params[:page_id])
47
+ @index = admin_page_taggings_path(@page)
48
+ @taggings = @page.taggings
49
+ elsif params[:post_id]
50
+ @post = Post.find_by_slug(params[:post_id])
51
+ @index = admin_post_taggings_path(@post)
52
+ @taggings = @post.taggings
53
+ elsif params[:image_id]
54
+ @image = Image.find(params[:image_id])
55
+ @project = Project.find(params[:project_id])
56
+ @index = admin_project_image_taggings_path(@project,@image)
57
+ @taggings = @image.taggings
58
+ elsif params[:project_id]
59
+ @project = Project.find(params[:project_id])
60
+ @index = admin_project_taggings_path(@project)
61
+ @taggings = @project.taggings
62
+ end
63
+ if params[:id]
64
+ @tagging = Tagging.find(params[:id])
65
+ @show = admin_page_tagging_path(@tagging)
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,11 @@
1
+ class Admin::TagsController < ApplicationController
2
+
3
+ def index
4
+ @tags = Tag.all
5
+ respond_to do |format|
6
+ format.json { render :json => @tags }
7
+ end
8
+ end
9
+
10
+
11
+ end
@@ -32,15 +32,16 @@ class AdminController < ActionController::Base
32
32
  @item.slug = @item.make_slug_unique(create_params[:slug])
33
33
  end
34
34
  if @item.save
35
- redirect_to @routes[:index], :notice => "#{@model.to_s} was successfully created."
35
+ @routes[:edit] = send("edit_admin_#{model_table_singular}_path", @item)
36
+ redirect_to @routes[:edit], :notice => "#{@model.to_s} was successfully created."
36
37
  else
38
+ @url = @routes[:index]
37
39
  render :action => "new"
38
40
  end
39
41
  end
40
42
 
41
43
  def update
42
44
  convert_dates if @item.attributes.has_key?('active_at')
43
- update_params ||= create_params
44
45
  if @item.attributes.has_key? 'slug' && !update_params[:slug].blank?
45
46
  update_params[:slug] = @item.make_slug_unique(update_params[:slug])
46
47
  end
@@ -48,6 +49,7 @@ class AdminController < ActionController::Base
48
49
  @routes[:edit] = send("edit_admin_#{model_table_singular}_path", @item)
49
50
  redirect_to @routes[:edit], :notice => "#{@model.to_s} was updated successfully."
50
51
  else
52
+ @url = @routes[:show]
51
53
  render :action => "edit"
52
54
  end
53
55
  end
@@ -85,4 +87,11 @@ class AdminController < ActionController::Base
85
87
  end
86
88
  end
87
89
 
90
+ def create_params
91
+ end
92
+
93
+ def update_params
94
+ create_params
95
+ end
96
+
88
97
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  # redirect to admin dashboard after signing in
4
4
  def after_sign_in_path_for(user)
5
- if current_user.is_admin?
5
+ <% if @admin == true %>if current_user.is_admin?
6
6
  admin_dashboard_path
7
7
  else
8
8
  root_path
9
- end
9
+ end<% else %>root_path<% end %>
10
10
  end
11
11
 
12
12
  # redirect back to sign in form when signed out
@@ -0,0 +1,45 @@
1
+ class Admin::ImagesController < ApplicationController
2
+
3
+ def index
4
+ @images = Image.all
5
+ respond_to do |format|
6
+ format.json { render :json => @images }
7
+ end
8
+ end
9
+
10
+ def edit
11
+ @url = @show
12
+ @image = Image.find(params[:id])
13
+ end
14
+
15
+ def create
16
+ @image = Image.new(create_params)
17
+ @image.save
18
+ end
19
+
20
+ def update
21
+ if @image.update_attributes(create_params)
22
+ redirect_to @project_edit, notice: 'Image was successfully updated.'
23
+ else
24
+ render action: "edit"
25
+ end
26
+ end
27
+
28
+ def destroy
29
+ @image = Image.find(params[:id])
30
+ @image.destroy
31
+ respond_to do |format|
32
+ format.json { render :nothing => true }
33
+ end
34
+ end
35
+
36
+
37
+ private
38
+
39
+ def create_params
40
+ params.require(:image).permit(
41
+ :filename, :crop_x, :crop_y, :crop_w, :crop_h
42
+ )
43
+ end
44
+
45
+ end
@@ -0,0 +1,12 @@
1
+ class PagesController < ApplicationController
2
+
3
+ def show
4
+ @page = Page.find_by_slug(params[:slug]) if @page.nil?
5
+ if @page
6
+ render "#{Rails.application.config.template_directory}/#{@page.template}"
7
+ else
8
+ raise ActionController::RoutingError.new('Not Found')
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ class PostsController < ApplicationController
2
+
3
+ def index
4
+ end
5
+
6
+ def show
7
+ @post = Post.find_by_slug(params[:slug])
8
+ raise ActionController::RoutingError.new('Not Found') unless @post.present?
9
+ end
10
+
11
+ end
@@ -0,0 +1,47 @@
1
+ module Admin::PagesHelper
2
+
3
+ def link_to_delete_page(page)
4
+ link_to 'Delete', admin_page_path(page), :method => :delete,
5
+ :data => { :confirm => SETTINGS['pages']['delete_warning'] }
6
+ end
7
+
8
+ def link_to_edit_page(page)
9
+ link_to 'Edit', edit_admin_page_path(page)
10
+ end
11
+
12
+ def page_template_field(type, name)
13
+ value = @page.template_data.nil? ? '' : @page.template_data[name]
14
+ html_output = ''
15
+ case type
16
+ when 'string'
17
+ html_output << <<-eos
18
+ <div class="control-group string required page_title">
19
+ <label class="string control-label" for="page_#{name}">
20
+ #{name.titleize}
21
+ </label>
22
+ <div class="controls">
23
+ <input class="string required"
24
+ id="page_#{name}"
25
+ name="page[template_data][#{name}]"
26
+ type="text"
27
+ value="#{value}">
28
+ </div>
29
+ </div>
30
+ eos
31
+ when 'text'
32
+ html_output << <<-eos
33
+ <div class="control-group string required page_title">
34
+ <label class="string control-label" for="page_#{name}">
35
+ #{name.titleize}
36
+ </label>
37
+ <div class="controls">
38
+ <textarea class="text required" id="page_#{name}"
39
+ name="page[template_data][#{name}]">#{value}</textarea>
40
+ </div>
41
+ </div>
42
+ eos
43
+ end
44
+ html_output
45
+ end
46
+
47
+ end
@@ -80,7 +80,7 @@ module AdminHelper
80
80
  # --------------------------------- Nav
81
81
 
82
82
  def admin_nav_items
83
- [
83
+ items = [
84
84
  {
85
85
  :label => 'Users',
86
86
  :icon => 'user',
@@ -0,0 +1,24 @@
1
+ module ImageCropper
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+
6
+ # We use these accessors to pass values to CarrierWave and RMagick without
7
+ # needing to store them in the database.
8
+ #
9
+ attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
10
+
11
+ # Like the accessors, this is used for cropping images.
12
+ #
13
+ after_update :crop_image
14
+ end
15
+
16
+ # This simply makes carrierwave and rmagick recreate all its versions. We only
17
+ # call it if the `crop_x` attribute is present, as we use that as our trigger.
18
+ # Otherwise, we're recreating versions without changing anything.
19
+ #
20
+ def crop_image
21
+ filename.recreate_versions! if crop_x.present?
22
+ end
23
+
24
+ end