tb_cms 1.2.3 → 1.3.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/assets/javascripts/admin/cms/menu_items.js +39 -17
  4. data/app/assets/stylesheets/admin/cms/application.css +11 -0
  5. data/app/controllers/admin/menu_items_controller.rb +103 -113
  6. data/app/controllers/admin/menus_controller.rb +52 -53
  7. data/app/controllers/admin/pages_controller.rb +107 -111
  8. data/app/controllers/admin/snippets_controller.rb +16 -16
  9. data/app/controllers/cms/sitemaps_controller.rb +5 -5
  10. data/app/controllers/pages_controller.rb +30 -34
  11. data/app/helpers/cms/application_helper.rb +184 -212
  12. data/app/models/concerns/cms_deprecated_multisite.rb +3 -3
  13. data/app/models/spud_menu.rb +4 -4
  14. data/app/models/spud_menu_item.rb +58 -61
  15. data/app/models/spud_page.rb +63 -67
  16. data/app/models/spud_page_partial.rb +42 -44
  17. data/app/models/spud_page_partial_revision.rb +3 -3
  18. data/app/models/spud_snippet.rb +7 -7
  19. data/app/views/admin/menu_items/index.html.erb +1 -1
  20. data/lib/generators/spud/cms/layout_generator.rb +8 -8
  21. data/lib/spud_cms/configuration.rb +10 -10
  22. data/lib/spud_cms/engine.rb +28 -28
  23. data/lib/spud_cms/liquid_snippet.rb +5 -7
  24. data/lib/spud_cms/page_route.rb +1 -1
  25. data/lib/spud_cms/template_parser.rb +35 -40
  26. data/lib/spud_cms/test_files.rb +6 -6
  27. data/lib/spud_cms/version.rb +3 -3
  28. data/spec/controllers/admin/menu_items_controller_spec.rb +54 -56
  29. data/spec/controllers/admin/menus_controller_spec.rb +31 -37
  30. data/spec/controllers/admin/pages_controller_spec.rb +31 -36
  31. data/spec/controllers/admin/snippets_controller_spec.rb +1 -1
  32. data/spec/controllers/pages_controller_spec.rb +21 -21
  33. data/spec/dummy/config/application.rb +3 -4
  34. data/spec/dummy/config/boot.rb +1 -1
  35. data/spec/dummy/config/environments/production.rb +1 -1
  36. data/spec/dummy/config/environments/test.rb +3 -3
  37. data/spec/dummy/config.ru +1 -1
  38. data/spec/dummy/db/migrate/20141231214447_create_spud_users.tb_core.rb +12 -12
  39. data/spec/dummy/db/migrate/20141231214448_add_time_zone_to_spud_user.tb_core.rb +0 -1
  40. data/spec/dummy/db/migrate/20141231214449_add_scope_to_spud_admin_permissions.tb_core.rb +0 -1
  41. data/spec/dummy/db/migrate/20141231214452_create_spud_permissions.tb_core.rb +3 -3
  42. data/spec/dummy/db/migrate/20141231214453_create_spud_role_permissions.tb_core.rb +2 -2
  43. data/spec/dummy/db/migrate/20141231214455_create_spud_permalinks.tb_permalinks.rb +1 -1
  44. data/spec/dummy/db/migrate/20141231214456_add_site_id_to_spud_permalinks.tb_permalinks.rb +1 -1
  45. data/spec/dummy/db/migrate/20141231214457_modify_site_id_for_spud_permalinks.tb_permalinks.rb +4 -4
  46. data/spec/dummy/db/migrate/20141231214459_create_spud_pages.tb_cms.rb +1 -1
  47. data/spec/dummy/db/migrate/20141231214461_create_spud_menu_items.tb_cms.rb +3 -3
  48. data/spec/dummy/db/migrate/20141231214463_create_spud_page_partials.tb_cms.rb +1 -1
  49. data/spec/dummy/db/migrate/20141231214464_add_visibility_to_spud_pages.tb_cms.rb +2 -2
  50. data/spec/dummy/db/migrate/20141231214466_add_use_custom_url_name_to_spud_pages.tb_cms.rb +1 -1
  51. data/spec/dummy/db/migrate/20141231214468_add_menu_id_to_spud_menu_items.tb_cms.rb +1 -1
  52. data/spec/dummy/db/migrate/20141231214469_add_classes_to_spud_menu_items.tb_cms.rb +0 -1
  53. data/spec/dummy/db/migrate/20141231214470_add_site_id_to_spud_pages.tb_cms.rb +2 -2
  54. data/spec/dummy/db/migrate/20141231214471_add_site_id_to_spud_templates.tb_cms.rb +2 -2
  55. data/spec/dummy/db/migrate/20141231214472_add_site_id_to_spud_menus.tb_cms.rb +2 -2
  56. data/spec/dummy/db/migrate/20141231214473_create_spud_page_partial_revisions.tb_cms.rb +1 -1
  57. data/spec/dummy/db/migrate/20141231214475_modify_site_id_for_spud_pages.tb_cms.rb +8 -8
  58. data/spec/dummy/db/migrate/20141231214478_create_spud_page_liquid_tags.tb_cms.rb +1 -1
  59. data/spec/dummy/db/migrate/20141231214479_create_spud_snippets.tb_cms.rb +1 -2
  60. data/spec/dummy/db/migrate/20141231214480_change_liquid_tags_to_polymorphic.tb_cms.rb +2 -2
  61. data/spec/dummy/db/migrate/20141231214481_drop_spud_page_liquid_tags.tb_cms.rb +6 -8
  62. data/spec/dummy/db/migrate/20150108164814_remove_site_id_from_cms_tables.tb_cms.rb +1 -0
  63. data/spec/dummy/db/migrate/20150911185843_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
  64. data/spec/dummy/db/migrate/20160215180157_create_tb_redirects.tb_redirects.rb +3 -3
  65. data/spec/dummy/db/schema.rb +142 -153
  66. data/spec/dummy/script/rails +2 -2
  67. data/spec/helpers/cms/application_helper_spec.rb +39 -41
  68. data/spec/models/spud_menu_item_spec.rb +13 -13
  69. data/spec/models/spud_page_partial_revision_spec.rb +1 -1
  70. data/spec/models/spud_page_partial_spec.rb +19 -20
  71. data/spec/models/spud_page_spec.rb +90 -91
  72. data/spec/models/spud_snippet_spec.rb +1 -1
  73. data/spec/rails_helper.rb +12 -6
  74. data/spec/spec_helper.rb +42 -44
  75. metadata +64 -38
  76. data/spec/authlogic_helper.rb +0 -2
@@ -1,81 +1,77 @@
1
1
  class SpudPage < ActiveRecord::Base
2
- include CmsDeprecatedMultisite
3
- include TbRedirects::HasRedirects
2
+ include CmsDeprecatedMultisite
3
+ include TbRedirects::HasRedirects
4
4
 
5
- spud_searchable
6
- belongs_to :spud_page
7
- has_many :spud_page_partial_revisions
8
- has_many :spud_pages, :dependent => :nullify
9
- has_many :spud_page_partials,:dependent => :destroy
10
- belongs_to :created_by_user,:class_name => "SpudUser",:foreign_key => :created_by
11
- belongs_to :updated_by_user,:class_name => "SpudUser",:foreign_key => :updated_by
5
+ spud_searchable
6
+ belongs_to :spud_page
7
+ has_many :spud_page_partial_revisions
8
+ has_many :spud_pages, dependent: :nullify
9
+ has_many :spud_page_partials, dependent: :destroy
10
+ belongs_to :created_by_user, class_name: 'SpudUser', foreign_key: :created_by
11
+ belongs_to :updated_by_user, class_name: 'SpudUser', foreign_key: :updated_by
12
12
 
13
- before_validation :generate_url_name
14
- validates :name, :presence => true, :uniqueness => {:scope => :spud_page_id}
15
- validates :url_name, :presence => true, :uniqueness => true
16
- after_update :create_redirect_if_necessary
13
+ before_validation :generate_url_name
14
+ validates :name, presence: true, uniqueness: { scope: :spud_page_id }
15
+ validates :url_name, presence: true, uniqueness: true
16
+ after_update :create_redirect_if_necessary
17
17
 
18
- accepts_nested_attributes_for :spud_page_partials, :allow_destroy => true
18
+ accepts_nested_attributes_for :spud_page_partials, allow_destroy: true
19
19
 
20
- scope :parent_pages, ->{ where(:spud_page_id => nil)}
21
- scope :published_pages, ->{ where(:published => true) }
22
- scope :viewable, ->{ where(:visibility => 0) }
20
+ scope :parent_pages, -> { where(spud_page_id: nil) }
21
+ scope :published_pages, -> { where(published: true) }
22
+ scope :viewable, -> { where(visibility: 0) }
23
23
 
24
- def full_content_processed
25
- self.spud_page_partials.collect{|partial| partial.content_processed }.join(' ')
26
- end
24
+ def full_content_processed
25
+ spud_page_partials.collect(&:content_processed).join(' ')
26
+ end
27
27
 
28
- def to_liquid
29
- return {'name' => self.name, 'url_name' => self.url_name}
30
- end
28
+ def to_liquid
29
+ return { 'name' => name, 'url_name' => url_name }
30
+ end
31
31
 
32
- # Returns an array of pages in order of heirarchy
33
- # :fitler Filters out a page by ID, and all of its children
34
- # :value Pick an attribute to be used in the value field, defaults to ID
35
- def self.options_tree_for_page(config={})
36
- collection = config[:collection] || self.all.group_by(&:spud_page_id)
37
- level = config[:level] || 0
38
- parent_id = config[:parent_id] || nil
39
- filter = config[:filter] || nil
40
- value = config[:value] || :id
41
- list = []
42
- if collection[parent_id]
43
- collection[parent_id].each do |c|
44
- if filter.blank? || c.id != filter.id
45
- list << [level.times.collect{ '- ' }.join('') + c.name, c[value]]
46
- list += self.options_tree_for_page({:collection => collection, :parent_id => c.id, :level => level+1, :filter => filter})
47
- end
48
- end
49
- end
50
- return list
51
- end
32
+ # Returns an array of pages in order of heirarchy
33
+ # :fitler Filters out a page by ID, and all of its children
34
+ # :value Pick an attribute to be used in the value field, defaults to ID
35
+ def self.options_tree_for_page(config = {})
36
+ collection = config[:collection] || all.group_by(&:spud_page_id)
37
+ level = config[:level] || 0
38
+ parent_id = config[:parent_id] || nil
39
+ filter = config[:filter] || nil
40
+ value = config[:value] || :id
41
+ list = []
42
+ collection[parent_id]&.each do |c|
43
+ if filter.blank? || c.id != filter.id
44
+ list << [Array.new(level) { '- ' }.join('') + c.name, c[value]]
45
+ list += options_tree_for_page(collection: collection, parent_id: c.id, level: level + 1, filter: filter)
46
+ end
47
+ end
48
+ return list
49
+ end
52
50
 
53
- def is_private?
54
- return self.visibility == 1
55
- end
51
+ def is_private?
52
+ return visibility == 1
53
+ end
56
54
 
57
- private
55
+ private
58
56
 
59
- def generate_url_name
60
- if url_name.blank?
61
- parts = []
62
- parts << spud_page.url_name if spud_page.present?
63
- parts << name.try(:parameterize)
64
- self.url_name = parts.join('/')
65
- end
66
- return true
67
- end
57
+ def generate_url_name
58
+ if url_name.blank?
59
+ parts = []
60
+ parts << spud_page.url_name if spud_page.present?
61
+ parts << name.try(:parameterize)
62
+ self.url_name = parts.join('/')
63
+ end
64
+ return true
65
+ end
68
66
 
69
- def create_redirect_if_necessary
70
- if url_name_changed?
71
- TbRedirect.create_smart({
72
- :source => "/#{url_name_was}",
73
- :destination => "/#{url_name}",
74
- :created_by => 'cms',
75
- :owner => self
76
- })
77
- end
78
- return true
79
- end
67
+ def create_redirect_if_necessary
68
+ if url_name_changed?
69
+ TbRedirect.create_smart(source: "/#{url_name_was}",
70
+ destination: "/#{url_name}",
71
+ created_by: 'cms',
72
+ owner: self)
73
+ end
74
+ return true
75
+ end
80
76
 
81
77
  end
@@ -1,52 +1,50 @@
1
1
  class SpudPagePartial < ActiveRecord::Base
2
- belongs_to :spud_page, :touch => true
3
- has_many :spud_liquid_tags, :as => :attachment, :dependent => :destroy
4
- validates :name,:presence => true
5
- before_save :maintain_revisions
6
- before_save :update_symbol_name
7
- acts_as_tb_liquid_content
2
+ belongs_to :spud_page, touch: true
3
+ has_many :spud_liquid_tags, as: :attachment, dependent: :destroy
4
+ validates :name, presence: true
5
+ before_save :maintain_revisions
6
+ before_save :update_symbol_name
7
+ acts_as_tb_liquid_content
8
8
 
9
- def update_symbol_name
10
- self.symbol_name = self.name.parameterize.underscore
11
- end
9
+ def update_symbol_name
10
+ self.symbol_name = name.parameterize.underscore
11
+ end
12
12
 
13
- def symbol_name
14
- return @symbol_name || self.name.parameterize.underscore
15
- end
13
+ def symbol_name
14
+ return @symbol_name || name.parameterize.underscore
15
+ end
16
16
 
17
- def postprocess_content
18
- @_template = Liquid::Template.parse(self.content)
19
- self.content_processed = @_template.render('page' => self.spud_page)
20
- end
17
+ def postprocess_content
18
+ @_template = Liquid::Template.parse(content)
19
+ self.content_processed = @_template.render('page' => spud_page)
20
+ end
21
21
 
22
- def content_processed=(content)
23
- write_attribute(:content_processed,content)
24
- end
22
+ def content_processed=(content)
23
+ self[:content_processed] = content
24
+ end
25
25
 
26
- def content_processed
27
- if read_attribute(:content_processed).blank?
28
- if self.new_record?
29
- self.content_processed = postprocess_content()
30
- else
31
- self.update_column(:content_processed, postprocess_content)
32
- end
33
- end
34
- return read_attribute(:content_processed)
35
- end
26
+ def content_processed
27
+ if self[:content_processed].blank?
28
+ if new_record?
29
+ self.content_processed = postprocess_content()
30
+ else
31
+ update_column(:content_processed, postprocess_content)
32
+ end
33
+ end
34
+ return self[:content_processed]
35
+ end
36
36
 
37
- def maintain_revisions
38
- if !self.changed.include?('content')
39
- return true
40
- end
41
- revision = SpudPagePartialRevision.new(:spud_page_id => self.spud_page_id,:name => self.name,:format => self.format,:content => self.content)
42
- revision.save
43
- if Spud::Cms.max_revisions > 0
44
- revision_count = SpudPagePartialRevision.where(:spud_page_id => self.spud_page_id,:name => self.name).count
45
- if revision_count > Spud::Cms.max_revisions
46
- revision_bye = SpudPagePartialRevision.where(:spud_page_id => self.spud_page_id,:name => self.name).order("created_at ASC").first
47
- revision_bye.destroy if !revision_bye.blank?
48
- end
49
- end
50
- return true
51
- end
37
+ def maintain_revisions
38
+ return true unless changed.include?('content')
39
+ revision = SpudPagePartialRevision.new(spud_page_id: spud_page_id, name: name, format: format, content: content)
40
+ revision.save
41
+ if Spud::Cms.max_revisions > 0
42
+ revision_count = SpudPagePartialRevision.where(spud_page_id: spud_page_id, name: name).count
43
+ if revision_count > Spud::Cms.max_revisions
44
+ revision_bye = SpudPagePartialRevision.where(spud_page_id: spud_page_id, name: name).order('created_at ASC').first
45
+ revision_bye.destroy unless revision_bye.blank?
46
+ end
47
+ end
48
+ return true
49
+ end
52
50
  end
@@ -1,5 +1,5 @@
1
1
  class SpudPagePartialRevision < ActiveRecord::Base
2
- belongs_to :spud_page
3
-
4
- #attr_accessible :name,:content,:format,:spud_page_id
2
+ belongs_to :spud_page
3
+
4
+ # attr_accessible :name,:content,:format,:spud_page_id
5
5
  end
@@ -1,25 +1,25 @@
1
1
  class SpudSnippet < ActiveRecord::Base
2
2
  include CmsDeprecatedMultisite
3
3
 
4
- validates :name, :presence => true
5
- validates_uniqueness_of :name
4
+ validates :name, presence: true
5
+ validates :name, uniqueness: true
6
6
 
7
7
  acts_as_tb_liquid_content
8
8
 
9
9
  def postprocess_content
10
- template = Liquid::Template.parse(self.content)
10
+ template = Liquid::Template.parse(content)
11
11
  self.content_processed = template.render()
12
12
  end
13
13
 
14
14
  def content_processed=(content)
15
- write_attribute(:content_processed,content)
15
+ self[:content_processed] = content
16
16
  end
17
17
 
18
18
  def content_processed
19
- if read_attribute(:content_processed).blank?
20
- self.update_column(:content_processed, postprocess_content)
19
+ if self[:content_processed].blank?
20
+ update_column(:content_processed, postprocess_content)
21
21
  end
22
- return read_attribute(:content_processed)
22
+ return self[:content_processed]
23
23
  end
24
24
 
25
25
  end
@@ -21,7 +21,7 @@
21
21
  <input type="hidden" value=<%= @menu.id %> id="menu-id">
22
22
  </div>
23
23
  <script type="text/javascript">
24
- $(document).ready(function() {spud.admin.cms.menu_items.init();})
24
+ $(document).ready(spud.admin.cms.menu_items.init);
25
25
  </script>
26
26
 
27
27
  <% end %>
@@ -1,22 +1,23 @@
1
1
  require 'rails/generators/migration'
2
2
 
3
3
  class Spud::Cms::LayoutGenerator < ::Rails::Generators::Base
4
- desc "This generator creates a new spud cms layout file"
5
- argument :template_name, :type => :string
6
- argument :attributes, :type => :array, :default => [], :banner => "content_block content_block"
4
+ desc 'This generator creates a new spud cms layout file'
5
+ argument :template_name, type: :string
6
+ argument :attributes, type: :array, default: [], banner: 'content_block content_block'
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
10
10
  def create_layout
11
- template "layout.html.erb", "app/views/layouts/#{template_name.downcase.underscore}.html.erb"
11
+ template 'layout.html.erb', "app/views/layouts/#{template_name.downcase.underscore}.html.erb"
12
12
  end
13
13
 
14
14
  def create_layout_action
15
15
  concern_path = 'app/controllers/concerns/spud_cms_layout_actions.rb'
16
- if !File.exist?(File.join(Rails.root, concern_path))
16
+ unless File.exist?(File.join(Rails.root, concern_path))
17
17
  template 'layout_actions.rb', 'app/controllers/concerns/spud_cms_layout_actions.rb'
18
18
  end
19
- inject_into_file concern_path, :after => "extend ActiveSupport::Concern\n" do <<-HEREDOC
19
+ inject_into_file concern_path, after: "extend ActiveSupport::Concern\n" do
20
+ <<-HEREDOC
20
21
 
21
22
  def #{template_name.downcase.underscore}_action(method)
22
23
  # this action is called when the #{template_name} cms layout is used
@@ -25,10 +26,9 @@ HEREDOC
25
26
  end
26
27
  end
27
28
 
28
- private
29
+ private
29
30
 
30
31
  def concern_content
31
-
32
32
  end
33
33
 
34
34
  end
@@ -2,25 +2,25 @@ module Spud
2
2
  module Cms
3
3
  include ActiveSupport::Configurable
4
4
 
5
- config_accessor :menus_enabled,:root_page_name,:yield_body_as_content_block,:default_page_layout,:enable_sitemap,:multisite_config,:max_revisions,:template_404, :cache_mode, :snippets_enabled
5
+ config_accessor :menus_enabled, :root_page_name, :yield_body_as_content_block, :default_page_layout, :enable_sitemap, :multisite_config, :max_revisions, :template_404, :cache_mode, :snippets_enabled
6
6
  self.menus_enabled = true
7
7
  self.snippets_enabled = false
8
- self.root_page_name = "home"
8
+ self.root_page_name = 'home'
9
9
  self.default_page_layout = 'application'
10
- self.yield_body_as_content_block = false
11
- self.cache_mode = nil #Options :full_page, :action
10
+ self.yield_body_as_content_block = false
11
+ self.cache_mode = nil # Options :full_page, :action
12
12
 
13
13
  self.enable_sitemap = true
14
14
  self.max_revisions = 10
15
15
  self.template_404 = 'not_found'
16
16
  self.multisite_config = []
17
17
  def self.site_config_for_short_name(short_name)
18
- configs = Spud::Cms.multisite_config.select{|p| p[:short_name].to_s == short_name.to_s}
19
- if configs.blank?
20
- return nil
21
- else
22
- return configs[0]
23
- end
18
+ configs = Spud::Cms.multisite_config.select { |p| p[:short_name].to_s == short_name.to_s }
19
+ if configs.blank?
20
+ return nil
21
+ else
22
+ return configs[0]
23
+ end
24
24
  end
25
25
 
26
26
  end
@@ -8,49 +8,49 @@ module Spud
8
8
  engine_name :tb_cms
9
9
 
10
10
  config.generators do |g|
11
- g.test_framework :rspec, :view_specs => false
11
+ g.test_framework :rspec, view_specs: false
12
12
  end
13
13
 
14
- initializer :admin do
15
- Spud::Core.configure do |config|
16
- config.admin_applications += [{:name => "Pages",:thumbnail => "admin/pages_thumb.png",:url => "/admin/pages",:order => 0}]
14
+ initializer :admin do
15
+ Spud::Core.configure do |config|
16
+ config.admin_applications += [{ name: 'Pages', thumbnail: 'admin/pages_thumb.png', url: '/admin/pages', order: 0 }]
17
17
  if Spud::Cms.menus_enabled
18
- config.admin_applications += [{:name => "Menus",:thumbnail => "admin/menus_thumb.png",:url => "/admin/menus",:order => 2}]
18
+ config.admin_applications += [{ name: 'Menus', thumbnail: 'admin/menus_thumb.png', url: '/admin/menus', order: 2 }]
19
19
  end
20
20
 
21
21
  if Spud::Cms.snippets_enabled
22
- config.admin_applications += [{:name => "Snippets",:thumbnail => "admin/snippets_thumb.png",:url => "/admin/snippets",:order => 3}]
22
+ config.admin_applications += [{ name: 'Snippets', thumbnail: 'admin/snippets_thumb.png', url: '/admin/snippets', order: 3 }]
23
23
  end
24
+ end
24
25
  end
25
- end
26
26
 
27
- initializer :model_overrides_cms do |config|
28
- ActiveRecord::Base.class_eval do
29
- include Spud::Searchable
27
+ initializer :model_overrides_cms do |_config|
28
+ ActiveRecord::Base.class_eval do
29
+ include Spud::Searchable
30
+ end
30
31
  end
31
- end
32
32
 
33
- initializer :spud_cms_routes do |config|
34
- config.routes_reloader.paths << File.expand_path('../page_route.rb', __FILE__)
35
- end
33
+ initializer :spud_cms_routes do |config|
34
+ config.routes_reloader.paths << File.expand_path('../page_route.rb', __FILE__)
35
+ end
36
36
 
37
- initializer 'tb_cms.assets' do |config|
38
- Spud::Core.append_admin_javascripts('admin/cms/application')
39
- Spud::Core.append_admin_stylesheets('admin/cms/application')
40
- Rails.application.config.assets.precompile += ['admin/pages_thumb.png', 'admin/snippets_thumb.png', 'admin/menus_thumb.png']
41
- end
37
+ initializer 'tb_cms.assets' do |_config|
38
+ Spud::Core.append_admin_javascripts('admin/cms/application')
39
+ Spud::Core.append_admin_stylesheets('admin/cms/application')
40
+ Rails.application.config.assets.precompile += ['admin/pages_thumb.png', 'admin/snippets_thumb.png', 'admin/menus_thumb.png']
41
+ end
42
42
 
43
- initializer :liquid do |config|
44
- Liquid::Template.register_tag('snippet', Spud::Cms::LiquidSnippet)
45
- end
43
+ initializer :liquid do |_config|
44
+ Liquid::Template.register_tag('snippet', Spud::Cms::LiquidSnippet)
45
+ end
46
46
 
47
- initializer :template_parser do |config|
48
- @template_parser = Spud::Cms::TemplateParser.new()
49
- end
47
+ initializer :template_parser do |_config|
48
+ @template_parser = Spud::Cms::TemplateParser.new()
49
+ end
50
50
 
51
- def template_parser
52
- return @template_parser
53
- end
51
+ def template_parser
52
+ return @template_parser
53
+ end
54
54
 
55
55
  end
56
56
  end
@@ -2,27 +2,25 @@ require 'liquid'
2
2
  module Spud
3
3
  module Cms
4
4
  class LiquidSnippet < Liquid::Tag
5
- def initialize(tag_name, snippet_name, tokens)
5
+ def initialize(_tag_name, snippet_name, _tokens)
6
6
  @snippet_name = snippet_name
7
- @snippet = SpudSnippet.where(:name => snippet_name).first
8
-
7
+ @snippet = SpudSnippet.where(name: snippet_name).first
9
8
  end
10
9
 
11
10
  def tag_name
12
- return "snippet"
11
+ return 'snippet'
13
12
  end
13
+
14
14
  def tag_value
15
15
  return @snippet_name
16
16
  end
17
17
 
18
- def render(context)
19
-
18
+ def render(_context)
20
19
  if !@snippet.blank?
21
20
  return @snippet.content_processed.html_safe
22
21
  else
23
22
  return ''
24
23
  end
25
-
26
24
  end
27
25
  end
28
26
  end
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- match "*id", :controller => "pages", :action => "show", :as => "page", :via => [:get, :post]
2
+ match '*id', controller: 'pages', action: 'show', as: 'page', via: [:get, :post]
3
3
  end
@@ -2,30 +2,27 @@ module Spud
2
2
  module Cms
3
3
  class TemplateParser
4
4
 
5
-
6
5
  def layouts
7
- if @layouts && Rails.env != 'development'
8
- return @layouts
9
- end
6
+ return @layouts if @layouts && Rails.env != 'development'
10
7
  @layouts = {}
11
8
  engines.each do |engine|
12
- @layouts.merge! process_layouts(engine.root.join('app','views','layouts'))
9
+ @layouts.merge! process_layouts(engine.root.join('app', 'views', 'layouts'))
13
10
  end
14
- @layouts.merge! process_layouts(Rails.application.root.join('app','views','layouts'))
11
+ @layouts.merge! process_layouts(Rails.application.root.join('app', 'views', 'layouts'))
15
12
 
16
13
  check_for_defaults(@layouts)
17
14
 
18
15
  return @layouts
19
16
  end
20
17
 
21
- private
18
+ private
22
19
 
23
20
  def process_layouts(filepath)
24
21
  layouts = {}
25
- Dir.glob(filepath.join("**","*.html.*")) do |template|
22
+ Dir.glob(filepath.join('**', '*.html.*')) do |template|
26
23
 
27
24
  layout = process_layout(template)
28
- layouts[layout_path(template)] = layout if !layout.blank?
25
+ layouts[layout_path(template)] = layout unless layout.blank?
29
26
 
30
27
  end
31
28
  return layouts
@@ -33,35 +30,35 @@ module Spud
33
30
 
34
31
  def process_layout(template)
35
32
  f = File.open(template)
36
- header = []
37
- f.each_line do |line|
38
- header << line
39
- break if line.blank?
40
- end
41
- f.close
42
- # puts header
43
- if header.blank? == false
44
- layout = {:partials => []}
33
+ header = []
34
+ f.each_line do |line|
35
+ header << line
36
+ break if line.blank?
37
+ end
38
+ f.close
39
+ # puts header
40
+ if header.blank? == false
41
+ layout = { partials: [] }
45
42
 
46
- header.each do |header_line|
47
- process_directive(header_line, layout)
48
- end
49
- layout[:partials] = ["Body"] if layout[:partials].blank?
50
- layout[:sites] = [Spud::Core.config.short_name.downcase] if layout[:sites].blank?
51
- if layout[:template_name].blank? == false
52
- return layout
53
- else
54
- return nil
55
- end
43
+ header.each do |header_line|
44
+ process_directive(header_line, layout)
56
45
  end
57
- return nil
46
+ layout[:partials] = ['Body'] if layout[:partials].blank?
47
+ layout[:sites] = [Spud::Core.config.short_name.downcase] if layout[:sites].blank?
48
+ if layout[:template_name].blank? == false
49
+ return layout
50
+ else
51
+ return nil
52
+ end
53
+ end
54
+ return nil
58
55
  end
59
56
 
60
57
  def check_for_defaults(layouts)
61
- default_layout_path = layout_path(Rails.application.root.join('app','views','layouts',Spud::Cms.default_page_layout))
62
- #puts(layouts)
58
+ default_layout_path = layout_path(Rails.application.root.join('app', 'views', 'layouts', Spud::Cms.default_page_layout))
59
+ # puts(layouts)
63
60
  if layouts[default_layout_path].blank?
64
- layouts[default_layout_path] = {:template_name => "Default", :partials => ["Body"], :sites => [Spud::Core.short_name.downcase], :default => true}
61
+ layouts[default_layout_path] = { template_name: 'Default', partials: ['Body'], sites: [Spud::Core.short_name.downcase], default: true }
65
62
  else
66
63
  layouts[default_layout_path][:default] = true
67
64
  end
@@ -69,16 +66,14 @@ module Spud
69
66
 
70
67
  def layout_path(template)
71
68
  dir, base = File.split(template)
72
- path_components = dir.split("/")
69
+ path_components = dir.split('/')
73
70
  component = path_components.shift
74
- while component != "layouts" do
75
- component = path_components.shift
76
- end
77
- path_components << base.downcase.split(".")[0]
78
- return "#{path_components.join("/")}"
71
+ component = path_components.shift while component != 'layouts'
72
+ path_components << base.downcase.split('.')[0]
73
+ return path_components.join('/').to_s
79
74
  end
80
75
 
81
- def process_directive(line,layout)
76
+ def process_directive(line, layout)
82
77
  if template_matcher = line.match(/\-?\#template\_name\:(.*)/)
83
78
  layout[:template_name] = template_matcher[1].strip
84
79
  end
@@ -86,7 +81,7 @@ module Spud
86
81
  layout[:partials] << template_matcher[1].strip
87
82
  end
88
83
  if template_matcher = line.match(/\-?\#site_name\:(.*)/)
89
- layout[:sites] = template_matcher[1].split(",").collect {|s| s.strip.downcase}
84
+ layout[:sites] = template_matcher[1].split(',').collect { |s| s.strip.downcase }
90
85
  end
91
86
  end
92
87
 
@@ -7,17 +7,17 @@ module Spud
7
7
  load_factories
8
8
  load_support
9
9
  end
10
-
10
+
11
11
  def load_specs
12
- Dir[File.join(File.expand_path('../../../', __FILE__), "spec/**/*_spec.rb")].each {|f| require f}
12
+ Dir[File.join(File.expand_path('../../../', __FILE__), 'spec/**/*_spec.rb')].each { |f| require f }
13
13
  end
14
-
14
+
15
15
  def load_factories
16
- Dir[File.join(File.expand_path('../../../', __FILE__), "factories/*")].each {|f| require f}
16
+ Dir[File.join(File.expand_path('../../../', __FILE__), 'factories/*')].each { |f| require f }
17
17
  end
18
-
18
+
19
19
  def load_support
20
- Dir[File.join(File.expand_path('../../../', __FILE__), "spec/support/**/*.rb")].each {|f| require f}
20
+ Dir[File.join(File.expand_path('../../../', __FILE__), 'spec/support/**/*.rb')].each { |f| require f }
21
21
  end
22
22
  end
23
23
  end