activeadmin-selleo-cms 0.0.14 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/app/admin/active_admin/views_helper.rb +8 -8
  2. data/app/admin/activeadmin_selleo_cms/asset.rb +1 -8
  3. data/app/admin/activeadmin_selleo_cms/page.rb +8 -6
  4. data/app/admin/activeadmin_selleo_cms/section.rb +44 -0
  5. data/app/assets/javascripts/activeadmin-selleo-cms/custom.js +1 -1
  6. data/app/assets/javascripts/ckeditor/config.js +171 -0
  7. data/app/controllers/cms_controller.rb +12 -0
  8. data/app/controllers/locales_controller.rb +6 -0
  9. data/app/controllers/pages_controller.rb +36 -0
  10. data/app/controllers/searches_controller.rb +6 -0
  11. data/app/helpers/pages_helper.rb +40 -0
  12. data/app/models/activeadmin_selleo_cms/icon.rb +1 -1
  13. data/app/models/activeadmin_selleo_cms/layout.rb +43 -2
  14. data/app/models/activeadmin_selleo_cms/page.rb +63 -10
  15. data/app/models/activeadmin_selleo_cms/section.rb +16 -0
  16. data/app/views/admin/assets/destroy.js.erb +1 -0
  17. data/app/views/admin/pages/_form.html.haml +11 -15
  18. data/app/views/admin/pages/_translated_fields.html.haml +11 -1
  19. data/app/views/admin/sections/_form.html.haml +36 -0
  20. data/app/views/pages/show.html.haml +5 -0
  21. data/app/views/{activeadmin_selleo_cms/searches → searches}/show.html.haml +0 -0
  22. data/config/initializers/active_admin.rb +6 -0
  23. data/config/initializers/i18n.rb +2 -0
  24. data/config/locales/cms.en.yml +2 -1
  25. data/config/routes.rb +12 -3
  26. data/db/migrate/20121129142932_create_activeadmin_selleo_cms_pages.rb +1 -1
  27. data/db/migrate/20130108153415_add_redirect_to_first_sub_page.rb +10 -0
  28. data/db/migrate/20130109132745_add_fields_to_page.rb +9 -0
  29. data/lib/activeadmin-selleo-cms/engine.rb +4 -0
  30. data/lib/activeadmin-selleo-cms/version.rb +1 -1
  31. data/lib/tasks/rebuild.rake +20 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +1 -5
  33. data/spec/dummy/app/views/layouts/cms.html.erb +11 -3
  34. data/spec/dummy/app/views/layouts/haml.html.haml +1 -0
  35. data/spec/dummy/db/migrate/{20130103215140_create_activeadmin_selleo_cms_pages.activeadmin_selleo_cms.rb → 20130117150800_create_activeadmin_selleo_cms_pages.activeadmin_selleo_cms.rb} +1 -1
  36. data/spec/dummy/db/migrate/{20130103215141_create_activeadmin_selleo_cms_locales.activeadmin_selleo_cms.rb → 20130117150801_create_activeadmin_selleo_cms_locales.activeadmin_selleo_cms.rb} +0 -0
  37. data/spec/dummy/db/migrate/{20130103215142_create_ckeditor_assets.activeadmin_selleo_cms.rb → 20130117150802_create_ckeditor_assets.activeadmin_selleo_cms.rb} +0 -0
  38. data/spec/dummy/db/migrate/{20130103215143_create_activeadmin_selleo_cms_sections.activeadmin_selleo_cms.rb → 20130117150803_create_activeadmin_selleo_cms_sections.activeadmin_selleo_cms.rb} +0 -0
  39. data/spec/dummy/db/migrate/{20130103215144_create_activeadmin_selleo_cms_searches.activeadmin_selleo_cms.rb → 20130117150804_create_activeadmin_selleo_cms_searches.activeadmin_selleo_cms.rb} +0 -0
  40. data/spec/dummy/db/migrate/{20130103215145_create_translations.activeadmin_selleo_cms.rb → 20130117150805_create_translations.activeadmin_selleo_cms.rb} +0 -0
  41. data/spec/dummy/db/migrate/{20130103215146_create_activeadmin_selleo_cms_assets.activeadmin_selleo_cms.rb → 20130117150806_create_activeadmin_selleo_cms_assets.activeadmin_selleo_cms.rb} +0 -0
  42. data/spec/dummy/db/migrate/20130117150807_add_redirect_to_first_sub_page.activeadmin_selleo_cms.rb +11 -0
  43. data/spec/dummy/db/migrate/20130117150808_add_fields_to_page.activeadmin_selleo_cms.rb +10 -0
  44. data/spec/dummy/db/schema.rb +9 -7
  45. data/spec/dummy/db/snapshots/test_database.sql +2 -2
  46. data/spec/dummy/log/test.log +125756 -0
  47. data/spec/dummy/tmp/cache/assets/CB7/190/sprockets%2F136a9350fa75f3336af293952861ed6d +0 -0
  48. data/spec/dummy/tmp/cache/assets/CD3/3E0/sprockets%2F373fa62090ab111ae606b963e1b8c793 +0 -0
  49. data/spec/dummy/tmp/cache/assets/D2C/2E0/sprockets%2Fa031c32e27ced12f81d4326f8b52fb23 +0 -0
  50. data/spec/dummy/tmp/cache/assets/D63/6C0/sprockets%2F1ae1f1cf9d92d0e61b7006171a39fd4d +0 -0
  51. data/spec/dummy/tmp/cache/assets/DB2/EA0/sprockets%2Ffead656b8b83fbae9f69435c33b4649d +0 -0
  52. data/spec/dummy/tmp/cache/assets/E37/3E0/sprockets%2F9e6d2d17ed6da64a2f1876d4cdfefcd1 +0 -0
  53. data/spec/dummy/tmp/capybara/capybara-201301081556598147527968.html +13 -0
  54. data/spec/dummy/tmp/capybara/capybara-201301081558042145012026.html +23 -0
  55. data/spec/dummy/tmp/capybara/capybara-201301081559296090328502.html +24 -0
  56. data/spec/dummy/tmp/capybara/capybara-201301101624594727125473.html +13 -0
  57. data/spec/dummy/tmp/capybara/capybara-201301101625068619114008.html +13 -0
  58. data/spec/dummy/tmp/capybara/capybara-201301101625104331710400.html +13 -0
  59. data/spec/dummy/tmp/capybara/capybara-201301101625154735808799.html +13 -0
  60. data/spec/factories/pages.rb +4 -2
  61. data/spec/models/activeadmin_selleo_cms/layout_spec.rb +4 -0
  62. data/spec/models/activeadmin_selleo_cms/page_spec.rb +98 -3
  63. data/spec/requests/pages_spec.rb +8 -0
  64. data/spec/spec_helper.rb +3 -2
  65. data/spec/support/pages_helper.rb +5 -2
  66. metadata +90 -41
  67. data/app/controllers/activeadmin_selleo_cms/application_controller.rb +0 -13
  68. data/app/controllers/activeadmin_selleo_cms/locales_controller.rb +0 -8
  69. data/app/controllers/activeadmin_selleo_cms/pages_controller.rb +0 -15
  70. data/app/controllers/activeadmin_selleo_cms/searches_controller.rb +0 -8
  71. data/app/helpers/activeadmin_selleo_cms/application_helper.rb +0 -31
  72. data/app/views/activeadmin_selleo_cms/pages/show.html.haml +0 -3
@@ -1,11 +1,11 @@
1
- def link_to_page(page)
2
- if page.is_link_url
3
- page.link_url
4
- else
5
- "/#{I18n.locale}/#{page.slug}"
6
- end
7
- end
8
-
9
1
  def set_admin_locale
10
2
  I18n.locale = :en
3
+ end
4
+
5
+ def determine_field_type(val)
6
+ if [TrueClass, FalseClass].include? val.class
7
+ :boolean
8
+ else
9
+ :string
10
+ end
11
11
  end
@@ -1,17 +1,10 @@
1
1
  ActiveAdmin.register ActiveadminSelleoCms::Asset, { as: 'Asset' } do
2
2
  config.batch_actions = false
3
3
 
4
- belongs_to :page
4
+ #belongs_to :page
5
5
 
6
6
  controller do
7
7
  respond_to :html, :js
8
-
9
- def destroy
10
- @page = ActiveadminSelleoCms::Page.find(params[:page_id])
11
- super do |format|
12
- format.js { render nothing: true }
13
- end
14
- end
15
8
  end
16
9
 
17
10
  end
@@ -1,17 +1,20 @@
1
1
  ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_asc" do
2
2
  config.batch_actions = false
3
- config.paginate = false
3
+ #config.paginate = false
4
+
5
+ actions :all, except: :show
4
6
 
5
7
  form :partial => "form"
6
8
 
9
+ filter :translations_title, as: :string
7
10
  filter :parent
8
11
 
9
- scope :roots, default: true
10
- scope :all
12
+ scope :roots
13
+ scope :all, default: true
11
14
 
12
15
  index do
13
16
  column :title do |page|
14
- page.breadcrumb
17
+ link_to page.breadcrumb, (page.children.any? ? (admin_pages_path(q: { parent_id_eq: page.id }, scope: :all)) : edit_admin_page_path( page.id ))
15
18
  end
16
19
  column :show_in_menu do |page|
17
20
  check_box_tag "activeadmin_selleo_cms_page[show_in_menu][#{page.id}]", 1, page.show_in_menu, data: { route: admin_page_path(page.id), id: page.id, resource: 'page', attribute: 'show_in_menu' }
@@ -26,8 +29,7 @@ ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_as
26
29
  l page.updated_at, format: :short
27
30
  end
28
31
  column :actions do |resource|
29
- links ||= link_to(I18n.t('active_admin.cms.view_on_site'), link_to_page(resource), :class => "member_link view_link", :target => "_new")
30
- links << link_to(I18n.t('active_admin.cms.sub_pages'), admin_pages_path(q: { parent_id_eq: resource.id }, scope: :all), :class => "member_link view_link")
32
+ links ||= link_to(I18n.t('active_admin.cms.view_on_site'), resource.url, :class => "member_link view_link", :target => "_new")
31
33
  links << link_to(I18n.t('active_admin.edit'), edit_resource_path(resource.id), :class => "member_link edit_link")
32
34
  links << link_to(I18n.t('active_admin.delete'), resource_path(resource.id), :method => :delete, :data => {:confirm => I18n.t('active_admin.delete_confirmation')}, :class => "member_link delete_link")
33
35
  end
@@ -0,0 +1,44 @@
1
+ ActiveAdmin.register ActiveadminSelleoCms::Section, as: "Section", sort_order: "name_asc" do
2
+ config.batch_actions = false
3
+ config.paginate = true
4
+
5
+ actions :all, except: :show
6
+
7
+ form :partial => "form"
8
+
9
+ scope :blurbs, default: true
10
+ scope :help
11
+
12
+ index do
13
+ column :name
14
+ column :created_at do |page|
15
+ l page.created_at, format: :short
16
+ end
17
+ column :updated_at do |page|
18
+ l page.updated_at, format: :short
19
+ end
20
+ column :actions do |resource|
21
+ links ||= link_to(I18n.t('active_admin.edit'), edit_resource_path(resource.id), :class => "member_link edit_link")
22
+ end
23
+ end
24
+
25
+ controller do
26
+ respond_to :html, :js
27
+
28
+ def create
29
+ create! do |success, failure|
30
+ success.html { redirect_to admin_sections_path }
31
+ failure.html { render action: :new }
32
+ end
33
+ end
34
+
35
+ def update
36
+ update! do |success, failure|
37
+ success.html { redirect_to admin_sections_path }
38
+ failure.html { render action: :edit }
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -18,7 +18,7 @@ var slug = function(str) {
18
18
 
19
19
  function delete_asset(page_id, asset_id) {
20
20
  $.ajax({
21
- url: '/admin/pages/' + page_id + '/assets/' + asset_id + '.js',
21
+ url: '/admin/assets/' + asset_id + '.js',
22
22
  type: 'DELETE'
23
23
  }).success(function(){
24
24
  $('[data-attachment-id="' + asset_id + '"]').remove();
@@ -0,0 +1,171 @@
1
+ /*
2
+ Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3
+ For licensing, see LICENSE.html or http://ckeditor.com/license
4
+ */
5
+
6
+ CKEDITOR.editorConfig = function( config )
7
+ {
8
+ // Define changes to default configuration here. For example:
9
+ // config.language = 'fr';
10
+ // config.uiColor = '#AADC6E';
11
+
12
+ /* Filebrowser routes */
13
+ // The location of an external file browser, that should be launched when "Browse Server" button is pressed.
14
+ config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
15
+
16
+ // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog.
17
+ config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";
18
+
19
+ // The location of a script that handles file uploads in the Flash dialog.
20
+ config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";
21
+
22
+ // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog.
23
+ config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
24
+
25
+ // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog.
26
+ config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
27
+
28
+ // The location of a script that handles file uploads in the Image dialog.
29
+ config.filebrowserImageUploadUrl = "/ckeditor/pictures";
30
+
31
+ // The location of a script that handles file uploads.
32
+ config.filebrowserUploadUrl = "/ckeditor/attachment_files";
33
+
34
+ // Rails CSRF token
35
+ config.filebrowserParams = function(){
36
+ var csrf_token, csrf_param, meta,
37
+ metas = document.getElementsByTagName('meta'),
38
+ params = new Object();
39
+
40
+ for ( var i = 0 ; i < metas.length ; i++ ){
41
+ meta = metas[i];
42
+
43
+ switch(meta.name) {
44
+ case "csrf-token":
45
+ csrf_token = meta.content;
46
+ break;
47
+ case "csrf-param":
48
+ csrf_param = meta.content;
49
+ break;
50
+ default:
51
+ continue;
52
+ }
53
+ }
54
+
55
+ if (csrf_param !== undefined && csrf_token !== undefined) {
56
+ params[csrf_param] = csrf_token;
57
+ }
58
+
59
+ return params;
60
+ };
61
+
62
+ config.addQueryString = function( url, params ){
63
+ var queryString = [];
64
+
65
+ if ( !params ) {
66
+ return url;
67
+ } else {
68
+ for ( var i in params )
69
+ queryString.push( i + "=" + encodeURIComponent( params[ i ] ) );
70
+ }
71
+
72
+ return url + ( ( url.indexOf( "?" ) != -1 ) ? "&" : "?" ) + queryString.join( "&" );
73
+ };
74
+
75
+ // Integrate Rails CSRF token into file upload dialogs (link, image, attachment and flash)
76
+ CKEDITOR.on( 'dialogDefinition', function( ev ){
77
+ // Take the dialog name and its definition from the event data.
78
+ var dialogName = ev.data.name;
79
+ var dialogDefinition = ev.data.definition;
80
+ var content, upload;
81
+
82
+ if (CKEDITOR.tools.indexOf(['link', 'image', 'attachment', 'flash'], dialogName) > -1) {
83
+ content = (dialogDefinition.getContents('Upload') || dialogDefinition.getContents('upload'));
84
+ upload = (content == null ? null : content.get('upload'));
85
+
86
+ if (upload && upload.filebrowser['params'] == null) {
87
+ upload.filebrowser['params'] = config.filebrowserParams();
88
+ upload.action = config.addQueryString(upload.action, upload.filebrowser['params']);
89
+ }
90
+ }
91
+
92
+ if (dialogName == 'link') {
93
+ var linkInfoTab = dialogDefinition.getContents('info');
94
+ var pageField = linkInfoTab.get('page');
95
+
96
+ if (!pageField) {
97
+ $.ajax({
98
+ url: '/en.json',
99
+ type: 'GET',
100
+ async: false
101
+ }).success(function(resp){
102
+ linkInfoTab.add( {
103
+ type : 'select',
104
+ label : 'Page',
105
+ id : 'page',
106
+ name : 'page',
107
+ items: resp,
108
+ onChange: function(ev){
109
+ var diag = CKEDITOR.dialog.getCurrent();
110
+ var url = diag.getContentElement('info','url');
111
+ var locale = $('[id*="lang"]:visible').find('input[name*="locale"]:hidden').val();
112
+ url.setValue(ev.data.value.replace(':locale', locale));
113
+ }
114
+ });
115
+ });
116
+ }
117
+ }
118
+ });
119
+
120
+ config.height = '200px';
121
+ config.width = '800px';
122
+
123
+ config.toolbar = 'Lite';
124
+
125
+ config.forcePasteAsPlainText = true;
126
+ config.fontSize_sizes = '12/12px;14/14px;18/18px;24/24px;30/30px;';
127
+
128
+ /* Extra plugins */
129
+ // works only with en, ru, uk locales
130
+ config.extraPlugins = "embed,attachment";
131
+
132
+ /* Toolbars */
133
+ config.toolbar = 'Lite';
134
+
135
+ config.toolbar_Easy =
136
+ [
137
+ ['Source','-','Preview'],
138
+ ['Cut','Copy','Paste','PasteText','PasteFromWord',],
139
+ ['Undo','Redo','-','SelectAll','RemoveFormat'],
140
+ ['Styles','Format'], ['Subscript', 'Superscript', 'TextColor'], ['Maximize','-','About'], '/',
141
+ ['Bold','Italic','Underline','Strike'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
142
+ ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
143
+ ['Link','Unlink','Anchor'], ['Image', 'Attachment', 'Flash', 'Embed'],
144
+ ['Table','HorizontalRule','Smiley','SpecialChar','PageBreak']
145
+ ];
146
+
147
+ config.toolbar_All =
148
+ [
149
+ ['Source', '-', 'Preview', 'Templates'],
150
+ ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
151
+ ['Maximize', '-', 'About'],
152
+ ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
153
+ ['Styles', 'Format'],
154
+ ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript', 'TextColor'],
155
+ ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
156
+ ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
157
+ ['Link', 'Unlink', 'Anchor'],
158
+ ['Image', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak']
159
+ ];
160
+
161
+ config.toolbar_Lite =
162
+ [
163
+ ['FontSize'],
164
+ ['Cut', 'Copy', 'Paste'],
165
+ ['Bold', 'Italic', 'Underline', 'StrikeThrough'],
166
+ ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull'],
167
+ ['Link', 'Unlink'],
168
+ ['BulletedList', 'HorizontalRule']
169
+ ];
170
+
171
+ };
@@ -0,0 +1,12 @@
1
+ class CmsController < ApplicationController
2
+
3
+ before_filter do
4
+ set_locale(params[:locale])
5
+ @available_locales = ActiveadminSelleoCms::Locale.enabled
6
+ end
7
+
8
+ def set_locale(locale_code = :en)
9
+ I18n.locale = locale_code
10
+ end
11
+
12
+ end
@@ -0,0 +1,6 @@
1
+ class LocalesController < ApplicationController
2
+ def show
3
+ I18n.locale = session[:locale_code] = params[:id]
4
+ redirect_to root_url
5
+ end
6
+ end
@@ -0,0 +1,36 @@
1
+ class PagesController < CmsController
2
+ before_filter :find_page, only: :show
3
+
4
+ private
5
+
6
+ def find_page
7
+ page_scope = ActiveadminSelleoCms::Page
8
+ root = ActiveadminSelleoCms::Page.root
9
+
10
+ raise "Create at least one page" unless root
11
+
12
+ if parent = ActiveadminSelleoCms::Page.find_by_slug(params[:page_id])
13
+ page_scope = page_scope.where(parent_id: parent.id)
14
+ end
15
+
16
+ @page = page_scope.find_by_slug(params[:id])
17
+
18
+ if !@page or (!@page.is_published? and @page != root)
19
+ redirect_to page_path(I18n.locale, root)
20
+ end
21
+ end
22
+
23
+ public
24
+
25
+ def show
26
+ @page.update_column(:views, (@page.views || 0) + 1)
27
+ render action: :show, layout: @page.layout_name
28
+ end
29
+
30
+ def index
31
+ respond_to do |format|
32
+ format.html { redirect_to page_path(I18n.locale, ActiveadminSelleoCms::Page.root) }
33
+ format.json { render text: ActiveadminSelleoCms::Page.published.map{|p| [p.title, p.url(locale: false)]}.to_json }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ class SearchesController < CmsController
2
+ def show
3
+ @results = ActiveadminSelleoCms::Search.current_locale.search_by_content(params[:id]).map(&:searchable).uniq
4
+ render action: :show, layout: 'search'
5
+ end
6
+ end
@@ -0,0 +1,40 @@
1
+ module PagesHelper
2
+ def link_to_locale(link_name, locale, page=nil)
3
+ if page
4
+ link_to link_name, page_path(locale.code, page.translated_attribute(:slug, locale.code))
5
+ elsif request.fullpath.match(/^\/\w{2}\/.*/)
6
+ link_to link_name, request.fullpath.gsub(/^\/(\w{2})\//, "/#{locale.code}/")
7
+ else
8
+ link_to link_name, "/#{locale.code}"
9
+ end
10
+ end
11
+
12
+ def link_to_search_result(result)
13
+ if result.is_a? ActiveadminSelleoCms::Page
14
+ link_to result, page_path(I18n.locale, result)
15
+ end
16
+ end
17
+
18
+ def url_to_page(page)
19
+ return "#" unless page
20
+ if page.is_link_url
21
+ page.link_url
22
+ elsif page.redirect_to_first_sub_page
23
+ page.children.published.any? ? url_to_page(page.children.published.first) : "#"
24
+ else
25
+ page_path(I18n.locale, page)
26
+ end
27
+ end
28
+
29
+ def link_to_page(page, link_name=nil)
30
+ link_to (link_name || page.title), url_to_page(page)
31
+ end
32
+
33
+ def s(name)
34
+ section = ActiveadminSelleoCms::Section.where(name: name).first_or_create
35
+ body = section.body.to_s
36
+ body = "" if body.match /<p>\s*<\/p>/
37
+ body += link_to(t("active_admin.cms.edit"), edit_admin_section_path(section)) if current_user and current_user.respond_to? :admin? and current_user.admin?
38
+ body.html_safe
39
+ end
40
+ end
@@ -3,7 +3,7 @@ module ActiveadminSelleoCms
3
3
  has_attached_file :data,
4
4
  :url => "/system/cms/icons/:id/:style_:basename.:extension",
5
5
  :path => ":rails_root/public/system/cms/icons/:id/:style_:basename.:extension",
6
- :styles => { :normal => "120x90#" },
6
+ :styles => { :normal => "120x90>" },
7
7
  :default_style => :normal
8
8
 
9
9
  validates_attachment_size :data, :less_than => 1.megabytes
@@ -1,10 +1,51 @@
1
- require 'texticle/rails'
1
+ require 'nokogiri'
2
2
  module ActiveadminSelleoCms
3
3
  class Layout
4
+
5
+ def initialize(path)
6
+ @path = path
7
+ @file = File.read(path)
8
+ @doc = Nokogiri::HTML(@file)
9
+ end
10
+
11
+ def section_names
12
+ @section_names ||= sections.map(&:name)
13
+ end
14
+
15
+ def sections
16
+ @sections ||= @doc.css('section[name]').map do |node|
17
+ Section.new(node)
18
+ end
19
+ end
20
+
21
+ def find_section(name)
22
+ sections.detect{|section| section.name == name}
23
+ end
24
+
4
25
  class << self
26
+ def find(name)
27
+ begin
28
+ Layout.new(Dir.glob(File.join(Rails.root, "app/views/layouts/#{name}.html.erb")).first)
29
+ rescue
30
+ nil
31
+ end
32
+ end
33
+
5
34
  def all
6
- Dir.glob(File.join(Rails.root, 'app/views/layouts/[a-z]*html*')).map{|l| l.split('/').last.split('.').first }
35
+ Dir.glob(File.join(Rails.root, 'app/views/layouts/[a-z]*html.erb')).map{|l| l.split('/').last.split('.').first }
36
+ end
37
+ end
38
+
39
+ class Section
40
+ attr_accessor :name, :type, :toolbar, :attachments
41
+
42
+ def initialize(node)
43
+ @name = node.attributes["name"].content
44
+ @attachments = node.attributes["attachments"] ? true : false
45
+ @type = node.attributes["data-type"] ? node.attributes["data-type"].content : 'ckeditor'
46
+ @toolbar = node.attributes["data-toolbar"] ? node.attributes["data-toolbar"].content : 'Easy'
7
47
  end
48
+
8
49
  end
9
50
  end
10
51
  end