comfortable_mexican_loveseat 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +36 -0
  4. data/Rakefile +34 -0
  5. data/app/controllers/comfy/admin/cms/base_controller.rb +63 -0
  6. data/app/controllers/comfy/admin/cms/layouts_controller.rb +71 -0
  7. data/app/controllers/comfy/cms/content_controller.rb +88 -0
  8. data/app/helpers/comfy/cms_helper.rb +104 -0
  9. data/app/models/comfy/cms/snippet.rb +45 -0
  10. data/app/views/comfy/admin/cms/files/_form.html.haml +23 -0
  11. data/app/views/comfy/admin/cms/files/index.html.haml +35 -0
  12. data/app/views/comfy/cms/content/render_sitemap.xml.builder +36 -0
  13. data/app/views/layouts/comfy/admin/cms/_flash.html.haml +4 -0
  14. data/lib/comfortable_mexican_loveseat.rb +14 -0
  15. data/lib/comfortable_mexican_loveseat/engine.rb +9 -0
  16. data/test/comfortable_mexican_loveseat_test.rb +7 -0
  17. data/test/dummy/README.rdoc +28 -0
  18. data/test/dummy/Rakefile +6 -0
  19. data/test/dummy/app/assets/javascripts/application.js +13 -0
  20. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  21. data/test/dummy/app/controllers/application_controller.rb +5 -0
  22. data/test/dummy/app/helpers/application_helper.rb +2 -0
  23. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  24. data/test/dummy/bin/bundle +3 -0
  25. data/test/dummy/bin/rails +4 -0
  26. data/test/dummy/bin/rake +4 -0
  27. data/test/dummy/bin/setup +29 -0
  28. data/test/dummy/config.ru +4 -0
  29. data/test/dummy/config/application.rb +26 -0
  30. data/test/dummy/config/boot.rb +5 -0
  31. data/test/dummy/config/database.yml +25 -0
  32. data/test/dummy/config/environment.rb +5 -0
  33. data/test/dummy/config/environments/development.rb +41 -0
  34. data/test/dummy/config/environments/production.rb +79 -0
  35. data/test/dummy/config/environments/test.rb +42 -0
  36. data/test/dummy/config/initializers/assets.rb +11 -0
  37. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  38. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  39. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/test/dummy/config/initializers/inflections.rb +16 -0
  41. data/test/dummy/config/initializers/mime_types.rb +4 -0
  42. data/test/dummy/config/initializers/session_store.rb +3 -0
  43. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/test/dummy/config/locales/en.yml +23 -0
  45. data/test/dummy/config/routes.rb +56 -0
  46. data/test/dummy/config/secrets.yml +22 -0
  47. data/test/dummy/public/404.html +67 -0
  48. data/test/dummy/public/422.html +67 -0
  49. data/test/dummy/public/500.html +66 -0
  50. data/test/dummy/public/favicon.ico +0 -0
  51. data/test/test_helper.rb +19 -0
  52. metadata +187 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6f9def9b413b9a46c941db32fee174e5284edfe
4
+ data.tar.gz: 22d877a65a24d2dd07aa795b8c65d30d47877d23
5
+ SHA512:
6
+ metadata.gz: e018cf29b977e5c94d2f47d46cc9ca0df06f1fce4148fd589586f0a8c8d37530cf8bc8369f9e924ce55a8ef3adc0e7f3c7e45d8fd2c398daaf444dc5f1101d8b
7
+ data.tar.gz: d05dc937df154ecbaaa7029472f7c465fb530d0d3494b87dd17efb4475a4b61e024bfe97552e483cfe5fe65b5282af3b55d8e2e3c830d4754d6b1eabf9756638
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Adam Bahlke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ = ComfortableMexicanLoveseat
2
+
3
+ The Comfortable Mexican Loveseat is an expansion pack to the Comfortable Mexican Sofa. It currently contains minor modifications to the <tt>snippet.rb</tt> and <tt>base_controller.rb</tt> files, improved sitemap functionality, and SEO-enhancing modifications.
4
+
5
+ The Loveseat references a fixed version of the CMS (currently 1.12.8) and latest releases are pulled in occasionally.
6
+
7
+ == SEO Features
8
+
9
+ === Custom Sitemaps
10
+
11
+ Building on the Sofa's sitemap functionality, the Loveseat lets you add Rails model show pages and custom routes to the sitemap.
12
+
13
+ To use it, please copy and customize the demo initializer located in <tt>templates/comfortable_mexican_loveseat.rb</tt> and in your <tt>routes.rb</tt> file make sure you have this line:
14
+
15
+ comfy_route :cms, :path => '/', :sitemap => true
16
+
17
+ Then replace your <tt>robots.txt</tt> file with the one in the templates folder.
18
+
19
+ === URL Redirection
20
+
21
+ By default when using the Loveseat, all trailing slash URLs ('myapp.com/example/') are redirected to a non-trailing slash URL.
22
+
23
+ === Page Meta Tags
24
+
25
+ By default when you create an application, it comes with meta description; page title; no-index; index; and canonical link fields that can be filled in on a per-page basis. To display these tags, add this to your <tt>application.html.erb</tt>:
26
+
27
+ <title><%= comfy_page_title %></title>
28
+ <%= comfy_seo_tags %>
29
+
30
+ === File Upload helper text
31
+
32
+ The Loveseat provides some helpful hints to admins when they're uploading images (choose an SEO-friendly name, add an alt-tag), which you can add to your locale files.
33
+
34
+ images_need_seo_friendly_names
35
+ files_alt_tag
36
+
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ComfortableMexicanLoveseat'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,63 @@
1
+ class Comfy::Admin::Cms::BaseController < ComfortableMexicanSofa.config.base_controller.to_s.constantize
2
+
3
+ include Comfy::Paginate
4
+
5
+ # Authentication module must have `authenticate` method
6
+ include ComfortableMexicanSofa.config.admin_auth.to_s.constantize
7
+
8
+ # Authorization module must have `authorize` method
9
+ include ComfortableMexicanSofa.config.admin_authorization.to_s.constantize
10
+
11
+ protect_from_forgery
12
+
13
+ before_action :authenticate,
14
+ :load_admin_site,
15
+ :set_locale,
16
+ :load_fixtures,
17
+ :except => :jump
18
+
19
+ layout 'comfy/admin/cms'
20
+
21
+ if ComfortableMexicanSofa.config.admin_cache_sweeper.present?
22
+ cache_sweeper *ComfortableMexicanSofa.config.admin_cache_sweeper
23
+ end
24
+
25
+ def jump
26
+ path = ComfortableMexicanSofa.config.admin_route_redirect
27
+ return redirect_to(path) unless path.blank?
28
+ load_admin_site
29
+ redirect_to comfy_admin_cms_site_pages_path(@site) if @site
30
+ end
31
+
32
+ protected
33
+
34
+ def load_admin_site
35
+ if @site = ::Comfy::Cms::Site.find_by_id(params[:site_id] || session[:site_id]) || ::Comfy::Cms::Site.first
36
+ session[:site_id] = @site.id
37
+ else
38
+ I18n.locale = ComfortableMexicanSofa.config.admin_locale || I18n.default_locale
39
+ flash[:danger] = I18n.t('comfy.admin.cms.base.site_not_found')
40
+ return redirect_to(new_comfy_admin_cms_site_path)
41
+ end
42
+ end
43
+
44
+ def set_locale
45
+ super
46
+ rescue
47
+ I18n.locale = cms_locale
48
+ end
49
+
50
+ def cms_locale
51
+ ComfortableMexicanSofa.config.admin_locale || (@site && @site.locale)
52
+ end
53
+
54
+ def load_fixtures
55
+ return unless ComfortableMexicanSofa.config.enable_fixtures
56
+
57
+ controllers = %w(layouts pages snippets files).collect{|c| 'comfy/admin/cms/' + c}
58
+ if controllers.member?(params[:controller]) && params[:action] == 'index'
59
+ ComfortableMexicanSofa::Fixture::Importer.new(@site.identifier).import!
60
+ flash.now[:danger] = I18n.t('comfy.admin.cms.base.fixtures_enabled')
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,71 @@
1
+ class Comfy::Admin::Cms::LayoutsController < Comfy::Admin::Cms::BaseController
2
+
3
+ before_action :build_layout, :only => [:new, :create]
4
+ before_action :load_layout, :only => [:edit, :update, :destroy]
5
+ before_action :authorize
6
+
7
+ def index
8
+ return redirect_to :action => :new if @site.layouts.count == 0
9
+ @layouts = @site.layouts.roots
10
+ end
11
+
12
+ def new
13
+ render
14
+ end
15
+
16
+ def edit
17
+ render
18
+ end
19
+
20
+ def create
21
+ @layout.save!
22
+ flash[:success] = I18n.t('comfy.admin.cms.layouts.created')
23
+ redirect_to :action => :edit, :id => @layout
24
+ rescue ActiveRecord::RecordInvalid
25
+ flash.now[:danger] = I18n.t('comfy.admin.cms.layouts.creation_failure')
26
+ render :action => :new
27
+ end
28
+
29
+ def update
30
+ @layout.update_attributes!(layout_params)
31
+ flash[:success] = I18n.t('comfy.admin.cms.layouts.updated')
32
+ redirect_to :action => :edit, :id => @layout
33
+ rescue ActiveRecord::RecordInvalid
34
+ flash.now[:danger] = I18n.t('comfy.admin.cms.layouts.update_failure')
35
+ render :action => :edit
36
+ end
37
+
38
+ def destroy
39
+ @layout.destroy
40
+ flash[:success] = I18n.t('comfy.admin.cms.layouts.deleted')
41
+ redirect_to :action => :index
42
+ end
43
+
44
+ def reorder
45
+ (params[:comfy_cms_layout] || []).each_with_index do |id, index|
46
+ ::Comfy::Cms::Layout.where(:id => id).update_all(:position => index)
47
+ end
48
+ render :nothing => true
49
+ end
50
+
51
+ protected
52
+
53
+ def build_layout
54
+ @layout = @site.layouts.new(layout_params)
55
+ @layout.parent ||= ::Comfy::Cms::Layout.find_by_id(params[:parent_id])
56
+ @layout.app_layout ||= @layout.parent.try(:app_layout)
57
+ @layout.content ||= "{{ cms:field:seo.old_page_url:string }}\n{{ cms:field:seo.meta_description:string }}\n{{ cms:field:seo.page_title:string }}\n{{ cms:field:seo.canonical_href:string }}\n{{ cms:field:seo.meta_index:string }}\n{{ cms:field:seo.meta_noindex:string }}\n{{ cms:page:content:rich_text }}"
58
+ end
59
+
60
+ def load_layout
61
+ @layout = @site.layouts.find(params[:id])
62
+ rescue ActiveRecord::RecordNotFound
63
+ flash[:danger] = I18n.t('comfy.admin.cms.layouts.not_found')
64
+ redirect_to :action => :index
65
+ end
66
+
67
+ def layout_params
68
+ params.fetch(:layout, {}).permit!
69
+ end
70
+
71
+ end
@@ -0,0 +1,88 @@
1
+ class Comfy::Cms::ContentController < Comfy::Cms::BaseController
2
+
3
+ # Authentication module must have `authenticate` method
4
+ include ComfortableMexicanSofa.config.public_auth.to_s.constantize
5
+
6
+ before_action :load_fixtures
7
+ before_action :load_cms_page,
8
+ :authenticate,
9
+ :only => :show
10
+
11
+ rescue_from ActiveRecord::RecordNotFound, :with => :page_not_found
12
+
13
+ def show
14
+
15
+ if @cms_page.target_page.present?
16
+ redirect_to @cms_page.target_page.url(:relative)
17
+ else
18
+ respond_to do |format|
19
+ format.html { render_page }
20
+ format.json { render :json => @cms_page }
21
+ end
22
+ end
23
+ end
24
+
25
+ def render_sitemap
26
+ render
27
+ end
28
+
29
+ protected
30
+
31
+ def render_page(status = 200)
32
+ if @cms_layout = @cms_page.layout
33
+ app_layout = (@cms_layout.app_layout.blank? || request.xhr?) ? false : @cms_layout.app_layout
34
+ render :inline => @cms_page.content_cache,
35
+ :layout => app_layout,
36
+ :status => status,
37
+ :content_type => mime_type
38
+ else
39
+ render :text => I18n.t('comfy.cms.content.layout_not_found'), :status => 404
40
+ end
41
+ end
42
+
43
+ # it's possible to control mimetype of a page by creating a `mime_type` field
44
+ def mime_type
45
+ mime_block = @cms_page.blocks.find_by_identifier(:mime_type)
46
+ mime_block && mime_block.content || 'text/html'
47
+ end
48
+
49
+ def load_fixtures
50
+ return unless ComfortableMexicanSofa.config.enable_fixtures
51
+ ComfortableMexicanSofa::Fixture::Importer.new(@cms_site.identifier).import!
52
+ end
53
+
54
+ def load_cms_page
55
+
56
+ page = @cms_site.pages.published.find_by_full_path("/#{params[:cms_path]}")
57
+
58
+ if page.present?
59
+ @cms_page = page
60
+ else
61
+ old_page = Comfy::Cms::Block.where(identifier: "seo.old_page_url", content: params[:cms_path].to_s).pluck(:content, :blockable_id, :blockable_type).first
62
+
63
+ if old_page.present?
64
+ if old_page.last == "Comfy::Cms::Page"
65
+ new_page = Comfy::Cms::Page.find_by(id: old_page.second)
66
+
67
+ if new_page.present?
68
+ redirect_to new_page.url(:relative), status: 301
69
+
70
+ return
71
+ end
72
+ end
73
+ end
74
+
75
+ page_not_found
76
+ end
77
+ end
78
+
79
+ def page_not_found
80
+ @cms_page = @cms_site.pages.published.find_by_full_path!('/404')
81
+
82
+ respond_to do |format|
83
+ format.html { render_page(404) }
84
+ end
85
+ rescue ActiveRecord::RecordNotFound
86
+ raise ActionController::RoutingError.new("Page Not Found at: \"#{params[:cms_path]}\"")
87
+ end
88
+ end
@@ -0,0 +1,104 @@
1
+ module Comfy::CmsHelper
2
+
3
+ def comfy_seo_tags
4
+ tags = []
5
+ tags << tag('meta', name: 'description', content: cms_block_content('seo.meta_description')) if cms_block_content('seo.meta_description').present?
6
+ tags << tag('meta', name: 'robots', content: cms_block_content('seo.meta_index')) if cms_block_content('seo.meta_index').present?
7
+ tags << tag('meta', name: 'robots', content: cms_block_content('seo.meta_noindex')) if cms_block_content('seo.meta_noindex').present?
8
+ tags << tag('link', rel: 'canonical', href: cms_block_content('seo.canonical_href')) if cms_block_content('seo.canonical_href').present?
9
+
10
+ return tags.join("\n").html_safe
11
+ end
12
+
13
+ def comfy_page_title
14
+ cms_block_content('seo.page_title')
15
+ end
16
+
17
+ def flash_css_class(type)
18
+ case type.to_sym
19
+ when :notice, :success then 'alert-success'
20
+ when :alert, :failure then 'alert-danger'
21
+ end
22
+ end
23
+
24
+ # Wrapper around ComfortableMexicanSofa::FormBuilder
25
+ def comfy_form_for(record, options = {}, &proc)
26
+ options[:builder] = ComfortableMexicanSofa::FormBuilder
27
+ options[:layout] ||= :horizontal
28
+ bootstrap_form_for(record, options, &proc)
29
+ end
30
+
31
+ # Injects some content somewhere inside cms admin area
32
+ def cms_hook(name, options = {})
33
+ ComfortableMexicanSofa::ViewHooks.render(name, self, options)
34
+ end
35
+
36
+ # Content of a snippet. Examples:
37
+ # cms_snippet_content(:my_snippet)
38
+ # <%= cms_snippet_content(:my_snippet) do %>
39
+ # Default content can go here.
40
+ # <% end %>
41
+ def cms_snippet_content(identifier, cms_site = @cms_site, &block)
42
+ unless cms_site
43
+ host, path = request.host_with_port.downcase, request.fullpath if respond_to?(:request) && request
44
+ cms_site = Comfy::Cms::Site.find_site(host, path)
45
+ end
46
+ return '' unless cms_site
47
+
48
+ snippet = cms_site.snippets.find_by_identifier(identifier)
49
+
50
+ if !snippet && block_given?
51
+ snippet = cms_site.snippets.create(
52
+ :identifier => identifier,
53
+ :label => identifier.to_s.titleize,
54
+ :content => capture(&block)
55
+ )
56
+ end
57
+
58
+ snippet ? snippet.content : ''
59
+ end
60
+
61
+ # Same as cms_snippet_content but cms tags will be expanded
62
+ def cms_snippet_render(identifier, cms_site = @cms_site, &block)
63
+ return '' unless cms_site
64
+ content = cms_snippet_content(identifier, cms_site, &block)
65
+ render :inline => ComfortableMexicanSofa::Tag.process_content(
66
+ cms_site.pages.build, ComfortableMexicanSofa::Tag.sanitize_irb(content)
67
+ )
68
+ end
69
+
70
+ # Content of a page block. This is how you get content from page:field
71
+ # Example:
72
+ # cms_block_content(:left_column, CmsPage.first)
73
+ # cms_block_content(:left_column) # if @cms_page is present
74
+ def cms_block_content(identifier, blockable = @cms_page)
75
+ tag = blockable && (block = blockable.blocks.find_by_identifier(identifier)) && block.tag
76
+ return '' unless tag
77
+ tag.content
78
+ end
79
+
80
+ # For those times when we need to render content that shouldn't be renderable
81
+ # Example: {{cms:field}} tags
82
+ def cms_block_content_render(identifier, blockable = @cms_page)
83
+ tag = blockable && (block = blockable.blocks.find_by_identifier(identifier)) && block.tag
84
+ return '' unless tag
85
+ render :inline => ComfortableMexicanSofa::Tag.process_content(blockable, tag.content)
86
+ end
87
+
88
+ # Same as cms_block_content but with cms tags expanded
89
+ def cms_block_render(identifier, blockable = @cms_page)
90
+ tag = blockable && (block = blockable.blocks.find_by_identifier(identifier)) && block.tag
91
+ return '' unless tag
92
+ render :inline => ComfortableMexicanSofa::Tag.process_content(blockable, tag.render)
93
+ end
94
+
95
+ # Wrapper to deal with Kaminari vs WillPaginate
96
+ def comfy_paginate(collection)
97
+ return unless collection
98
+ if defined?(WillPaginate)
99
+ will_paginate collection
100
+ elsif defined?(Kaminari)
101
+ paginate collection, :theme => 'comfy'
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,45 @@
1
+ class Comfy::Cms::Snippet < ActiveRecord::Base
2
+ self.table_name = 'comfy_cms_snippets'
3
+
4
+ cms_is_categorized
5
+ cms_is_mirrored
6
+ cms_has_revisions_for :content
7
+
8
+ # -- Relationships --------------------------------------------------------
9
+ belongs_to :site
10
+
11
+ # -- Callbacks ------------------------------------------------------------
12
+ before_validation :assign_label
13
+ before_create :assign_position
14
+ after_save :clear_page_content_cache
15
+ after_destroy :clear_page_content_cache
16
+
17
+ # -- Validations ----------------------------------------------------------
18
+ validates :site_id,
19
+ :presence => true
20
+ validates :label,
21
+ :presence => true
22
+ validates :identifier,
23
+ :presence => true,
24
+ :uniqueness => { :scope => :site_id },
25
+ :format => { :with => /\A\w[\/a-z0-9_-]*\z/i }
26
+
27
+ # -- Scopes ---------------------------------------------------------------
28
+ default_scope -> { order('comfy_cms_snippets.position') }
29
+
30
+ protected
31
+
32
+ def assign_label
33
+ self.label = self.label.blank?? self.identifier.try(:titleize) : self.label
34
+ end
35
+
36
+ def clear_page_content_cache
37
+ Comfy::Cms::Page.where(:id => site.pages.pluck(:id)).update_all(:content_cache => nil)
38
+ end
39
+
40
+ def assign_position
41
+ max = self.site.snippets.maximum(:position)
42
+ self.position = max ? max + 1 : 0
43
+ end
44
+
45
+ end