page_engine 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/app/assets/javascripts/page_engine.js +53 -50
  2. data/app/assets/stylesheets/page_engine.css +2 -0
  3. data/app/controllers/admin/pages_controller.rb +1 -3
  4. data/app/helpers/pages_helper.rb +64 -71
  5. data/app/models/page.rb +6 -18
  6. data/app/views/admin/pages/_form.html.haml +3 -3
  7. data/app/views/admin/pages/_page_part_fields.html.haml +1 -1
  8. data/app/views/admin/pages/duplicate.js.erb +0 -4
  9. data/app/views/admin/pages/index.html.haml +1 -1
  10. data/app/views/pages/_nav_item.html.haml +1 -1
  11. data/lib/generators/page_engine/install/install_generator.rb +64 -0
  12. data/lib/page_engine/extensions.rb +12 -8
  13. data/lib/page_engine/instance_methods.rb +6 -6
  14. data/lib/page_engine.rb +31 -0
  15. data/spec/dummy/app/assets/stylesheets/application.css +250 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  17. data/spec/dummy/app/views/layouts/application.html.haml +5 -3
  18. data/spec/dummy/config/initializers/page_engine.rb +13 -0
  19. data/spec/dummy/db/development.sqlite3 +0 -0
  20. data/spec/dummy/log/development.log +18618 -0
  21. data/spec/dummy/tmp/cache/assets/BF5/7E0/sprockets%2F1681222188324d465309541f4e71f6e8 +0 -0
  22. data/spec/dummy/tmp/cache/assets/C1F/4A0/sprockets%2Fb257125f39b2a708d678262f26152408 +0 -0
  23. data/spec/dummy/tmp/cache/assets/C38/BB0/sprockets%2F122300de3f3142028abb055394919a47 +0 -0
  24. data/spec/dummy/tmp/cache/assets/C51/920/sprockets%2F3522c83d77303240c3548fdd7d186194 +0 -0
  25. data/spec/dummy/tmp/cache/assets/C54/B60/sprockets%2F08007599d13c8b8205959be4709d103d +0 -0
  26. data/spec/dummy/tmp/cache/assets/C83/E20/sprockets%2F2d6f03d170965f27d7626502373e8cd2 +0 -0
  27. data/spec/dummy/tmp/cache/assets/C8E/6D0/sprockets%2F10a754e99f089474b072c71eeb960954 +0 -0
  28. data/spec/dummy/tmp/cache/assets/CAD/1B0/sprockets%2F12cb3832e2e7e34236067e9e350b8c73 +0 -0
  29. data/spec/dummy/tmp/cache/assets/CB8/880/sprockets%2F3b651a5763758db2fc0347488e69a3e1 +0 -0
  30. data/spec/dummy/tmp/cache/assets/CBA/0A0/sprockets%2F2983f7dd6130a7c24892da333c18d779 +0 -0
  31. data/spec/dummy/tmp/cache/assets/CD0/CA0/sprockets%2F719e10ea5f5b1c20b6518a1d3432774e +0 -0
  32. data/spec/dummy/tmp/cache/assets/CD1/EB0/sprockets%2Fba17700b36ee975c05d06042a6af9631 +0 -0
  33. data/spec/dummy/tmp/cache/assets/CD5/8B0/sprockets%2F31178c43077cb48bfc81217ad0872cd1 +0 -0
  34. data/spec/dummy/tmp/cache/assets/CDA/A30/sprockets%2Fd1a7692303d59c495dd61cd1d41246b5 +0 -0
  35. data/spec/dummy/tmp/cache/assets/CDD/D20/sprockets%2F070d2bf7a81574ee0e560e174737a17f +0 -0
  36. data/spec/dummy/tmp/cache/assets/CE0/CD0/sprockets%2Fd206c4ec51748382823dee1e7f28055a +0 -0
  37. data/spec/dummy/tmp/cache/assets/CE3/690/sprockets%2F9531c78d64b8651a60dd128573bbe7e1 +0 -0
  38. data/spec/dummy/tmp/cache/assets/CE3/C10/sprockets%2F05a63f093f971cd73662695fab452b0f +0 -0
  39. data/spec/dummy/tmp/cache/assets/CE7/770/sprockets%2F56570f527d86457c48485cedb2d1c30c +0 -0
  40. data/spec/dummy/tmp/cache/assets/CEE/2B0/sprockets%2F75f58ee42279991f91ac43260b9b0fe3 +0 -0
  41. data/spec/dummy/tmp/cache/assets/CF2/E60/sprockets%2F6cf94481464e607960899cc38adac2b6 +0 -0
  42. data/spec/dummy/tmp/cache/assets/D09/2D0/sprockets%2F731ea2f82a086d10ff127d30c994f53b +0 -0
  43. data/spec/dummy/tmp/cache/assets/D0D/000/sprockets%2Fbb689a9183e1482be8c02ab4f536083b +0 -0
  44. data/spec/dummy/tmp/cache/assets/D13/FF0/sprockets%2Fd62e2814c718d1a22c84c7b3a78eb948 +0 -0
  45. data/spec/dummy/tmp/cache/assets/D16/BA0/sprockets%2F141f6d67a3871387dc3a1a9963de0de7 +0 -0
  46. data/spec/dummy/tmp/cache/assets/D17/DD0/sprockets%2F04f75f0ecb38c984675d23a9144d2be7 +0 -0
  47. data/spec/dummy/tmp/cache/assets/D1A/140/sprockets%2Fe5dbcc46887452182b85e8da04994ea0 +0 -0
  48. data/spec/dummy/tmp/cache/assets/D1F/620/sprockets%2F5eb71efe5276c4b5c148cd75958e2760 +0 -0
  49. data/spec/dummy/tmp/cache/assets/D23/570/sprockets%2Fb79b2bd85b952ef68724f54e3344dd66 +0 -0
  50. data/spec/dummy/tmp/cache/assets/D26/4D0/sprockets%2Faa9fd545084f66b324662ca8f48c88f9 +0 -0
  51. data/spec/dummy/tmp/cache/assets/D27/2F0/sprockets%2F6b6e52b5006574d3fef8d34ef639978d +0 -0
  52. data/spec/dummy/tmp/cache/assets/D30/ED0/sprockets%2Fea74cc14e1532ac70f928d8d205c5a13 +0 -0
  53. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  54. data/spec/dummy/tmp/cache/assets/D33/E40/sprockets%2F06b596c4052fc9ad352a54ac0871cf2c +0 -0
  55. data/spec/dummy/tmp/cache/assets/D3B/4D0/sprockets%2Faf8a08611a00ade8c7f16d626708eb67 +0 -0
  56. data/spec/dummy/tmp/cache/assets/D3E/740/sprockets%2F62194496bd7f322f3b2f6f2bf602e1fb +0 -0
  57. data/spec/dummy/tmp/cache/assets/D3F/170/sprockets%2F13df698b0cd7e1f7045913a1c6a96cc4 +0 -0
  58. data/spec/dummy/tmp/cache/assets/D3F/7C0/sprockets%2F42286191d1dec5e46ae8f89a0af0d147 +0 -0
  59. data/spec/dummy/tmp/cache/assets/D40/720/sprockets%2Fe798537f2ae8abbbac509070c9e06506 +0 -0
  60. data/spec/dummy/tmp/cache/assets/D45/CF0/sprockets%2F577ac52ab81ab676640dda59969cce32 +0 -0
  61. data/spec/dummy/tmp/cache/assets/D47/1D0/sprockets%2F904ef275b101c77ee529b4fe7cf323f7 +0 -0
  62. data/spec/dummy/tmp/cache/assets/D4A/D90/sprockets%2F4f476e9f41ff71e1045d03fc36de6c66 +0 -0
  63. data/spec/dummy/tmp/cache/assets/D4C/EE0/sprockets%2F7ee487bf0d625668f3fcb075c89a420d +0 -0
  64. data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
  65. data/spec/dummy/tmp/cache/assets/D60/DB0/sprockets%2Fb2b29acaab38e7049fd950a381e05f11 +0 -0
  66. data/spec/dummy/tmp/cache/assets/D68/450/sprockets%2F7290abaa3947f361fb72cb333692beaf +0 -0
  67. data/spec/dummy/tmp/cache/assets/D69/910/sprockets%2F05abeb33740bac77bef60b5445695c8c +0 -0
  68. data/spec/dummy/tmp/cache/assets/D6B/230/sprockets%2F744429c3ae6d8aadf46550ee21cc58b1 +0 -0
  69. data/spec/dummy/tmp/cache/assets/D6C/7E0/sprockets%2Fd3abe581052fc2ffd33b9f465b477b14 +0 -0
  70. data/spec/dummy/tmp/cache/assets/D70/280/sprockets%2F99a543e2b6be1d37c3ccc8a90261f87a +0 -0
  71. data/spec/dummy/tmp/cache/assets/D70/330/sprockets%2F292913c88244b67cdb46da1eed327fda +0 -0
  72. data/spec/dummy/tmp/cache/assets/D71/520/sprockets%2F018fdf705225eaa53bc9c287ebd68c91 +0 -0
  73. data/spec/dummy/tmp/cache/assets/D71/5D0/sprockets%2Fc8e0dae5e23b4b3941152e3b87e7f7c6 +0 -0
  74. data/spec/dummy/tmp/cache/assets/D73/830/sprockets%2F38d93d829b7d163c372f3acd557c2eab +0 -0
  75. data/spec/dummy/tmp/cache/assets/D74/120/sprockets%2Ffbe442bef82371edd6525fe5622de319 +0 -0
  76. data/spec/dummy/tmp/cache/assets/D77/7C0/sprockets%2Fcf660249e6eb81370e70cfe24d771dfe +0 -0
  77. data/spec/dummy/tmp/cache/assets/D7C/660/sprockets%2Fbb4ce966494c0b544c7ea5f4e9c2b866 +0 -0
  78. data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  79. data/spec/dummy/tmp/cache/assets/D87/FA0/sprockets%2Fed7ffae98375a3c9819ee641f00e388d +0 -0
  80. data/spec/dummy/tmp/cache/assets/D92/E50/sprockets%2F09a8ce459d99efe497507cad2ed88f56 +0 -0
  81. data/spec/dummy/tmp/cache/assets/D93/670/sprockets%2Fdf4cd8447459d7b31b077d0af7aba00b +0 -0
  82. data/spec/dummy/tmp/cache/assets/D94/0C0/sprockets%2Fac68f40dcce2850b0fdd7dfb91505115 +0 -0
  83. data/spec/dummy/tmp/cache/assets/D96/AE0/sprockets%2F6c450fd116d891f54a32bcfcbd4b762b +0 -0
  84. data/spec/dummy/tmp/cache/assets/DA2/0E0/sprockets%2F71a404ff712a059b23edee96c9bfcd75 +0 -0
  85. data/spec/dummy/tmp/cache/assets/DA6/860/sprockets%2Ff5526cc6647cdd14b05aed999377abbc +0 -0
  86. data/spec/dummy/tmp/cache/assets/DA7/5F0/sprockets%2Fe92688bcadd7fcddd86227c04b9712e1 +0 -0
  87. data/spec/dummy/tmp/cache/assets/DA7/6A0/sprockets%2Fa6745bdd80053c25a9ee2d81e96adef9 +0 -0
  88. data/spec/dummy/tmp/cache/assets/DA9/890/sprockets%2Fd1501c9a42bbc34f0cc11eae60b2e22e +0 -0
  89. data/spec/dummy/tmp/cache/assets/DB7/5A0/sprockets%2Fd2fac77222901b5da4abcf1c225d91db +0 -0
  90. data/spec/dummy/tmp/cache/assets/DBE/A90/sprockets%2F40e8db6da00eac4d36841aa33ff46fb3 +0 -0
  91. data/spec/dummy/tmp/cache/assets/DC6/E60/sprockets%2F415f6a64519b7c8ae296dbbafeb105ba +0 -0
  92. data/spec/dummy/tmp/cache/assets/DC8/660/sprockets%2Fbafd7b9ed0b0c06ed5e283463ad4c547 +0 -0
  93. data/spec/dummy/tmp/cache/assets/DCA/BB0/sprockets%2F1a792cae50966aef0d0d4131fe5fafd9 +0 -0
  94. data/spec/dummy/tmp/cache/assets/DD0/D40/sprockets%2Fc5ad6e6949709508d0dbdb0b1a7ecbe9 +0 -0
  95. data/spec/dummy/tmp/cache/assets/DD9/E90/sprockets%2Fd44526e0ec17dcbbccf7e14db768e869 +0 -0
  96. data/spec/dummy/tmp/cache/assets/DDC/270/sprockets%2Fadb8f369db4f8784c76fd2ee1d3633ac +0 -0
  97. data/spec/dummy/tmp/cache/assets/DDE/420/sprockets%2F69cf180e779eb3095cebe85edbfc22b7 +0 -0
  98. data/spec/dummy/tmp/cache/assets/DE0/250/sprockets%2F1559ff83d17dd6b788d6ab7fada65ee1 +0 -0
  99. data/spec/dummy/tmp/cache/assets/DE1/B40/sprockets%2F9c7deec5e90b5957c6d5b31ded7fe074 +0 -0
  100. data/spec/dummy/tmp/cache/assets/DFB/2A0/sprockets%2F801140d7903bfebe6accecc7fc9f71e2 +0 -0
  101. data/spec/dummy/tmp/cache/assets/E01/830/sprockets%2F3359db498c5ca08b6ff0a5fe54c8acda +0 -0
  102. data/spec/dummy/tmp/cache/assets/E04/7E0/sprockets%2Fee9c0f735fc2fed82f00e66fa71bc91d +0 -0
  103. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  104. data/spec/dummy/tmp/cache/assets/E32/C40/sprockets%2Faade2bb8a94be3f057fe7d4a6fd65a84 +0 -0
  105. data/spec/dummy/tmp/cache/assets/E51/940/sprockets%2F5c78b0ffb0472ccdce1fea8dad2142bf +0 -0
  106. data/spec/dummy/tmp/cache/assets/E70/2B0/sprockets%2F7eedcfada8bf8bff28c96d9ea93521d3 +0 -0
  107. data/spec/dummy/tmp/pids/server.pid +1 -0
  108. data/vendor/assets/javascripts/codemirror/codemirror.js +2164 -0
  109. data/vendor/assets/javascripts/codemirror/modes/css.js +124 -0
  110. data/vendor/assets/javascripts/codemirror/modes/javascript.js +348 -0
  111. data/vendor/assets/javascripts/codemirror/overlay.js +51 -0
  112. data/vendor/assets/javascripts/codemirror/runmode.js +27 -0
  113. data/vendor/assets/stylesheets/codemirror/codemirror.css +68 -0
  114. data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +17 -0
  115. data/vendor/assets/stylesheets/codemirror/themes/default.css +19 -0
  116. data/vendor/assets/stylesheets/codemirror/themes/elegant.css +9 -0
  117. data/vendor/assets/stylesheets/codemirror/themes/neat.css +8 -0
  118. data/vendor/assets/stylesheets/codemirror/themes/night.css +20 -0
  119. metadata +194 -18
  120. data/lib/generators/page_engine/page_engine_generator.rb +0 -60
@@ -6,6 +6,9 @@
6
6
  //= require markitup/sets/css/set
7
7
  //= require markitup/sets/javascript/set
8
8
  //= require jquery.ui.nestedSortable
9
+ //= require codemirror/codemirror
10
+ //= require codemirror/modes/javascript
11
+ //= require codemirror/modes/css
9
12
 
10
13
  $(document).ready(function(){
11
14
 
@@ -50,6 +53,14 @@ $(document).ready(function(){
50
53
  return false;
51
54
  });
52
55
 
56
+ $('select.filter').live('change', function(){
57
+ check_filter($(this));
58
+ });
59
+
60
+ $('select.filter').each(function(){
61
+ check_filter($(this));
62
+ });
63
+
53
64
  $('textarea[data-filter=css]').each(function(){
54
65
  add_css($(this));
55
66
  });
@@ -57,50 +68,6 @@ $(document).ready(function(){
57
68
  $('textarea[data-filter=javascript]').each(function(){
58
69
  add_javascript($(this));
59
70
  });
60
-
61
- $('textarea[data-filter=textile]').each(function(){
62
- add_textile($(this));
63
- });
64
-
65
- $('textarea[data-filter=markdown]').each(function(){
66
- add_markdown($(this));
67
- });
68
-
69
- $('textarea[data-filter=html]').each(function(){
70
- add_html($(this));
71
- });
72
-
73
- $('select.filter').live('change', function(){
74
- textarea = $('#' + $(this).attr('rel'));
75
- filter = textarea.attr('data-filter');
76
-
77
- switch ($(this).val()){
78
- case 'html':
79
- add_html(textarea)
80
- textarea.attr('data-filter', 'html');
81
- break;
82
- case 'textile':
83
- add_textile(textarea);
84
- textarea.attr('data-filter', 'textile');
85
- break;
86
- case 'markdown':
87
- add_markdown(textarea);
88
- textarea.attr('data-filter', 'markdown');
89
- break;
90
- case 'erb':
91
- remove_editors(textarea);
92
- textarea.attr('data-filter', 'erb');
93
- break;
94
- case 'erb+textile':
95
- add_textile(textarea)
96
- textarea.attr('data-filter', 'erb+textile');
97
- break;
98
- case 'none':
99
- remove_editors(textarea);
100
- textarea.attr('data-filter', 'none');
101
- break;
102
- }
103
- });
104
71
 
105
72
  $('#page_no_publish_window').change(function(){
106
73
  $('.edit_page .field.publish_from').toggle('slide');
@@ -129,6 +96,37 @@ $(document).ready(function(){
129
96
  });
130
97
  });
131
98
 
99
+ check_filter = function(filter){
100
+ textarea = $('#' + filter.attr('rel'));
101
+
102
+ switch (filter.val()){
103
+ case 'html':
104
+ add_html(textarea)
105
+ textarea.attr('data-filter', 'html');
106
+ break;
107
+ case 'textile':
108
+ add_textile(textarea);
109
+ textarea.attr('data-filter', 'textile');
110
+ break;
111
+ case 'markdown':
112
+ add_markdown(textarea);
113
+ textarea.attr('data-filter', 'markdown');
114
+ break;
115
+ case 'erb':
116
+ remove_editors(textarea);
117
+ textarea.attr('data-filter', 'erb');
118
+ break;
119
+ case 'erb+textile':
120
+ add_textile(textarea)
121
+ textarea.attr('data-filter', 'erb+textile');
122
+ break;
123
+ case 'none':
124
+ remove_editors(textarea);
125
+ textarea.attr('data-filter', 'none');
126
+ break;
127
+ }
128
+ }
129
+
132
130
  add_html = function(textarea){
133
131
  remove_editors(textarea);
134
132
  textarea.markItUp(markitup_html_settings);
@@ -148,15 +146,19 @@ add_markdown = function(textarea){
148
146
  }
149
147
 
150
148
  add_css = function(textarea){
151
- remove_editors(textarea);
152
- textarea.markItUp(markitup_css_settings);
153
- textarea.parents('.markItUp').addClass('css');
149
+ CodeMirror.fromTextArea(document.getElementById(textarea.attr('id')), {
150
+ lineNumbers: true,
151
+ matchBrackets: true,
152
+ mode: 'css'
153
+ });
154
154
  }
155
155
 
156
156
  add_javascript = function(textarea){
157
- remove_editors(textarea);
158
- textarea.markItUp(markitup_javascript_settings);
159
- textarea.parents('.markItUp').addClass('javascript');
157
+ CodeMirror.fromTextArea(document.getElementById(textarea.attr('id')), {
158
+ lineNumbers: true,
159
+ matchBrackets: true,
160
+ mode: 'javascript'
161
+ });
160
162
  }
161
163
 
162
164
  remove_editors = function(textarea){
@@ -185,5 +187,6 @@ add_fields = function(link, association, content){
185
187
  } else {
186
188
  alert('You need to specify a name');
187
189
  }
190
+ return false;
188
191
  }
189
192
 
@@ -6,6 +6,8 @@
6
6
  *= require markitup/sets/markdown/style
7
7
  *= require markitup/sets/css/style
8
8
  *= require markitup/sets/javascript/style
9
+ *= require codemirror/codemirror
10
+ *= require codemirror/themes/default
9
11
  */
10
12
 
11
13
  .js .hidden {
@@ -26,10 +26,9 @@ class Admin::PagesController < ApplicationController
26
26
  # GET /pages/new.xml
27
27
  def new
28
28
  @page = Page.new
29
- Page.page_parts.collect { |page_part| @page.page_parts.build(:title => page_part) }
29
+ PageEngine.page_parts.collect { |page_part| @page.page_parts.build(:title => page_part) }
30
30
  @parent = Page.find_by_permalink(params[:page_id])
31
31
  @roles = PageEngine.class_exists?('Role') ? Role.all : []
32
- @page_part_index = 0
33
32
 
34
33
  respond_to do |format|
35
34
  format.html # new.html.erb
@@ -44,7 +43,6 @@ class Admin::PagesController < ApplicationController
44
43
  @page = @page.first
45
44
  @parent = @page.parent
46
45
  @roles = PageEngine.class_exists?('Role') ? Role.all : []
47
- @page_part_index = 0
48
46
  end
49
47
 
50
48
  # POST /pages
@@ -10,11 +10,11 @@ module PagesHelper
10
10
  end
11
11
 
12
12
  def page_js(options={})
13
- default_options = {
14
- 'with_tags' => true
15
- }.merge(options.stringify_keys)
13
+ options = {
14
+ :with_tags => true
15
+ }.with_indifferent_access.merge(options)
16
16
 
17
- if default_options['with_tags']
17
+ if options[:with_tags]
18
18
  if @page && !@page.js.blank?
19
19
  javascript_tag do
20
20
  @page.js
@@ -26,11 +26,11 @@ module PagesHelper
26
26
  end
27
27
 
28
28
  def page_css(options={})
29
- default_options = {
30
- 'with_tags' => true
31
- }.merge(options.stringify_keys)
29
+ options = {
30
+ :with_tags => true
31
+ }.with_indifferent_access.merge(options)
32
32
 
33
- if default_options['with_tags']
33
+ if options[:with_tags]
34
34
  if @page && !@page.css.blank?
35
35
  content_tag :style do
36
36
  @page.css
@@ -97,30 +97,30 @@ module PagesHelper
97
97
 
98
98
  # Return the specified page part content
99
99
  def page_content(options={})
100
- default_options = {
101
- 'page' => @page,
102
- 'part' => 'body'
103
- }.merge!(options.stringify_keys)
100
+ options = {
101
+ :page => @page,
102
+ :part => 'body'
103
+ }.with_indifferent_access.merge(options)
104
104
 
105
- default_options['page'].page_parts.detect { |p| p.title == default_options['part'].to_s } if default_options['page']
105
+ options[:page].page_parts.detect { |p| p.title == options[:part].to_s } if options[:page]
106
106
  end
107
107
 
108
108
  def page_snippet(name, options={})
109
- default_options = {
110
- 'default_text' => 'Page snippet not found',
111
- 'tag' => nil,
112
- 'class' => ['page_snippet'],
113
- 'id' => nil
114
- }.merge(options.stringify_keys)
109
+ options = {
110
+ :default_text => 'Page snippet not found',
111
+ :tag => nil,
112
+ :class => ['page_snippet'],
113
+ :id => nil
114
+ }.with_indifferent_access.merge(options)
115
115
 
116
116
  page_snippet = PageSnippet.find_by_name(name.to_s)
117
117
 
118
- if default_options['tag']
119
- content_tag default_options['tag'], :class => default_options['class'], :id => default_options['id'] do
120
- page_snippet ? page_snippet : default_options['default_text']
118
+ if options[:tag]
119
+ content_tag options[:tag], :class => options[:class], :id => options[:id] do
120
+ page_snippet ? page_snippet : options[:default_text]
121
121
  end
122
122
  else
123
- page_snippet ? page_snippet : default_options['default_text']
123
+ page_snippet ? page_snippet : options[:default_text]
124
124
  end
125
125
  end
126
126
 
@@ -142,76 +142,69 @@ module PagesHelper
142
142
  # * seperator: The text or character that will seperate the breadcrumbs. Defaults to " &raquo; "
143
143
  # * format: choices are "ul" or "inline". "ul" displays the breadcrumb links in an unordered list whilst "inline" displays them inline in a containing div. Defaults to "ul"
144
144
  def breadcrumbs(options={})
145
- default_options = {
146
- 'breadcrumbs' => @breadcrumbs,
147
- 'page' => @page,
148
- 'seperator' => ' &raquo; ',
149
- 'format' => 'ul'
150
- }.merge!(options.stringify_keys)
145
+ options = {
146
+ :breadcrumbs => @breadcrumbs,
147
+ :page => @page,
148
+ :seperator => ' &raquo; ',
149
+ :format => :ul
150
+ }.with_indifferent_access.merge(options)
151
151
 
152
- case default_options['format'].to_s
153
- when 'inline'
154
- content_tag :div, :class => 'breadcrumbs' do
155
- links = default_options['breadcrumbs'].collect.with_index { |breadcrumb, i| link_to_page(breadcrumb, :class => "crumb_#{i}") + default_options['seperator'].html_safe }.join().html_safe
156
- links += content_tag(:span, replace_title_for(default_options['page']), :class => 'current_page') if default_options['page']
152
+ case options[:format]
153
+ when :inline
154
+ content_tag :div, :class => :breadcrumbs do
155
+ links = options[:breadcrumbs].collect.with_index { |breadcrumb, i| link_to_page(breadcrumb, :class => "crumb_#{i}") + options[:seperator].html_safe }.join().html_safe
156
+ links += content_tag(:span, replace_title_for(options[:page]), :class => 'current_page') if options[:page]
157
157
  end
158
158
 
159
- when 'ul'
160
- content_tag :ul, :class => 'breadcrumbs' do
161
- links = default_options['breadcrumbs'].collect.with_index { |breadcrumb, i| content_tag(:li, link_to_page(breadcrumb, :class => "crumb_#{i}")) }.join().html_safe
162
- links += content_tag(:li, replace_title_for(default_options['page']), :class => 'current_page') if default_options['page']
159
+ when :ul
160
+ content_tag :ul, :class => :breadcrumbs do
161
+ links = options[:breadcrumbs].collect.with_index { |breadcrumb, i| content_tag(:li, link_to_page(breadcrumb, :class => "crumb_#{i}")) }.join().html_safe
162
+ links += content_tag(:li, replace_title_for(options[:page]), :class => 'current_page') if options[:page]
163
163
  end
164
164
 
165
165
  else
166
- 'Please choose one of \'inline\' or \'ul\' as a format'
166
+ 'Please choose one of :inline or :ul as a format'
167
167
  end
168
168
  end
169
169
 
170
170
  # Options:
171
+ # * root: The root of the navigation structure
171
172
  # * current: The current_page if not @page
172
173
  # * depth: The number of levels in the tree to traverse. Defaults to 2
173
174
  # * class: The class of the containing ul. Defaults to ""
174
175
  # * id: The id of the containing id. Defaults to ""
175
- # * link_current: Set to true if the current page should have a link. Defaults to false
176
- def navigation(permalink, options={})
177
- default_options = {
178
- 'current' => @page,
179
- 'class' => 'nav',
180
- 'id' => '',
181
- 'include_root' => false,
182
- 'link_current' => false,
183
- 'depth' => 2
184
- }.merge!(options.stringify_keys)
176
+ # * link_current: Set to true if the current page should have a link. Defaults to false
177
+ def navigation(options={})
178
+ options = {
179
+ :root => nil,
180
+ :current => @page,
181
+ :class => 'nav',
182
+ :id => '',
183
+ :include_root => false,
184
+ :link_current => false,
185
+ :depth => 2
186
+ }.with_indifferent_access.merge(options)
185
187
 
186
188
  current_user = nil unless defined?(current_user)
187
-
188
- root_page = Page.published_or_hidden.viewable_by(current_user)
189
189
 
190
- if permalink
191
- root_page = root_page.find_by_permalink(permalink.to_s)
190
+ if options[:root].is_a?(NilClass)
191
+ root_page = Page.published_or_hidden.viewable_by(current_user).root_only.first
192
+ elsif options[:root].is_a?(Page)
193
+ root_page = options[:root]
194
+ elsif options[:root].is_a?(String)
195
+ root_page = Page.published_or_hidden.viewable_by(current_user).where('pages.url = :root or pages.permalink = :root', :root => options[:root]).first
196
+ elsif options[:root].is_a?(Hash)
197
+ options[:root].stringify_keys!
198
+ root_page = Page.published_or_hidden.viewable_by(current_user).where(:controller => options[:root][:controller], :action => options[:root][:action]).first
192
199
  else
193
- root_page = root_page.first
200
+ return "<p><em>Error:</em> Root must be a page, a permalink, a url or a hash containing the controller and action, got: #{root.class.to_s}.</p>".html_safe
194
201
  end
195
202
 
196
- return "<p><em>Error:</em> Root page not found</p>".html_safe unless root_page
203
+ return "<p><em>Error:</em> Root page not found: #{options[:root]}</p>".html_safe unless root_page
197
204
 
198
- grouped_pages = root_page.self_and_descendants.viewable_by(current_user).shown_in_menu.published.group_by(&:parent_id)
205
+ grouped_pages = root_page.self_and_descendants.viewable_by(current_user).shown_in_menu.published.for_nav.group_by(&:parent_id)
199
206
 
200
- render 'pages/navigation', :options => default_options, :root_page => root_page, :grouped_pages => grouped_pages, :level => 1
201
- end
202
-
203
- def filter_select(target, options={})
204
- default_options = {
205
- 'builder' => nil,
206
- 'object' => nil,
207
- 'attribute' => nil
208
- }.merge!(options.stringify_keys)
209
-
210
- if default_options['builder']
211
- default_options['builder'].select(default_options['attribute'], Page.filters, {}, { :class => 'filter', :rel => target })
212
- else
213
- select_tag(default_options['object'], default_options['attribute'], Page.filters, {}, { :class => 'filter', :rel => target })
214
- end
207
+ render 'pages/navigation', :options => options, :root_page => root_page, :grouped_pages => grouped_pages, :level => 1
215
208
  end
216
209
 
217
210
  private
data/app/models/page.rb CHANGED
@@ -42,6 +42,7 @@ class Page < ActiveRecord::Base
42
42
  scope :shown_in_sitemap, where({ :display_in_sitemap => true })
43
43
  scope :shown_in_menu, where({ :display_in_menu => true })
44
44
  scope :just_controller_and_actions, select("controller || '|' || action as taken").group('taken')
45
+ scope :for_nav, select([:id, :title, :parent_id, :menu_css_class, :no_link, :url, :controller, :action, :permalink])
45
46
 
46
47
  attr_accessor :no_publish_window, :controller_action
47
48
 
@@ -112,7 +113,7 @@ class Page < ActiveRecord::Base
112
113
  page
113
114
  end
114
115
 
115
- def is_viewable_by? user
116
+ def is_viewable_by?(user)
116
117
  if PageEngine.class_exists?('Role')
117
118
  if PageEngine.class_exists?('User') && user
118
119
  return true if self.roles.length == 0
@@ -151,27 +152,14 @@ class Page < ActiveRecord::Base
151
152
  end
152
153
 
153
154
  class << self
154
- attr_accessor :layouts
155
155
 
156
- def breadcrumbs_for user, url
156
+ def breadcrumbs_for(user, url)
157
157
  root = Page.published.viewable_by(user).find_by_url(url)
158
158
  root.nil? ? [] : root.self_and_ancestors
159
159
  end
160
-
161
- def status_values
162
- ["Draft", "Published", "Review", "Hidden"]
163
- end
164
160
 
165
161
  def default_layout
166
- Page.layouts.first
167
- end
168
-
169
- def filters
170
- %w{ none html textile markdown erb erb+textile }
171
- end
172
-
173
- def page_parts
174
- %w{ body left right header footer }
162
+ PageEngine.layouts.first
175
163
  end
176
164
 
177
165
  # Scopes
@@ -189,7 +177,7 @@ class Page < ActiveRecord::Base
189
177
  end
190
178
  end
191
179
 
192
- def with_roles roles
180
+ def with_roles(roles)
193
181
  if Extras.class_exists?('Role')
194
182
  includes(:roles).where([ "roles.id IN (?)", roles.join(',') ])
195
183
  else
@@ -197,7 +185,7 @@ class Page < ActiveRecord::Base
197
185
  end
198
186
  end
199
187
 
200
- def with_url request, params
188
+ def with_url(request, params)
201
189
  url = request.fullpath
202
190
  url.gsub!(/\?.*/, '') # Strip away anything after the ? as it's not needed
203
191
 
@@ -29,20 +29,20 @@
29
29
  = f.input :js, :label => 'Javascript', :input_html => { 'data-filter' => 'javascript' }
30
30
  = f.input :meta_description
31
31
  = f.input :meta_keywords
32
- = f.input :status, :as => :select, :collection => Page.status_values, :include_blank => false
32
+ = f.input :status, :as => :select, :collection => PageEngine.statuses, :include_blank => false
33
33
  = f.input :no_publish_window, :as => :boolean
34
34
  = f.input :publish_from, :order => [:day, :month, :year]
35
35
  = f.input :publish_to, :order => [:day, :month, :year]
36
36
  = f.input :url
37
37
 
38
- = f.input :controller_action do
38
+ = f.input :controller_action, :as => :select do
39
39
  = f.select :controller_action, grouped_options_for_select(@routes), :include_blank => true
40
40
 
41
41
  = f.input :display_in_menu
42
42
  = f.input :display_in_sitemap
43
43
  = f.input :menu_css_class
44
44
  = f.input :no_link
45
- = f.input :layout, :as => :select, :collection => Page.layouts, :include_blank => false
45
+ = f.input :layout, :as => :select, :collection => PageEngine.layouts, :include_blank => false
46
46
 
47
47
  - if PageEngine.class_exists?('Asset')
48
48
  .field.attached_assets
@@ -5,5 +5,5 @@
5
5
  = f.error_notification
6
6
 
7
7
  = f.input :title, :class => 'page_part_title'
8
- = f.input :filter, :collection => Page.filters, :include_blank => false, :class => 'filter', :input_html => { :class => 'filter', :rel => "page_part_content_#{f.object.id}" }
8
+ = f.input :filter, :collection => PageEngine.filters, :include_blank => false, :class => 'filter', :input_html => { :class => 'filter', :rel => "page_part_content_#{f.object.id}" }
9
9
  = f.input :content, :input_html => { 'data-filter' => f.object.filter, :class => 'editor ignore_tab', :id => "page_part_content_#{f.object.id}" }
@@ -1,5 +1 @@
1
1
  $('#page_<%= @original_page.id %>').after('<%= escape_javascript(render @page) %>');
2
- page_sort();
3
- <% flash.each do |level, message| -%>
4
- flash_message('<%= escape_javascript(message) %>', '<%= level %>');
5
- <% end -%>
@@ -1,6 +1,6 @@
1
1
  %h2 Pages
2
2
  %p
3
- = link_to 'New root page', new_admin_page_path, :class => 'icon_left add'
3
+ = link_to('New root page', new_admin_page_path, :class => 'icon_left add')
4
4
 
5
5
  %ol#page_engine.list{ 'data-href' => sort_admin_pages_path }
6
6
  = render @pages[nil] if @pages[nil]
@@ -1,5 +1,5 @@
1
1
  %li{ :class => page_menu_class(page) }
2
- - if page.no_link || (page == options[:current] && !options[:link_current])
2
+ - if page.no_link || (page == options['current'] && !options['link_current'])
3
3
  %span= replace_title_for(page)
4
4
  - else
5
5
  = link_to_page(page)
@@ -0,0 +1,64 @@
1
+ module PageEngine
2
+ module Generators
3
+ require 'rails/generators'
4
+ require 'rails/generators/migration'
5
+
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ desc "This generator installs PageEngine supporting assets"
9
+
10
+ source_root File.expand_path('../../../../', __FILE__)
11
+
12
+ def self.next_migration_number(path)
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
+ end
15
+
16
+ def install
17
+ create_migrations
18
+ copy_stylesheets
19
+ copy_javascripts
20
+ copy_images
21
+
22
+ copy_file 'app/views/layouts/admin.html.haml', 'app/views/layouts/admin.html.haml'
23
+ end
24
+
25
+ private
26
+
27
+ def create_migrations
28
+ begin
29
+ migration_template 'db/migrate/20110814185929_create_page_engine.rb', 'db/migrate/create_page_engine.rb'
30
+ rescue Exception => e
31
+ puts e
32
+ end
33
+ end
34
+
35
+ def copy_stylesheets
36
+ directory 'app/assets/stylesheets', 'public/stylesheets'
37
+ directory 'vendor/assets/stylesheets', 'public/stylesheets'
38
+
39
+ puts 'Updating image location'
40
+ ['css', 'textile', 'markdown', 'html', 'javascript'].each do |area|
41
+ gsub_file "public/stylesheets/markitup/sets/#{area}/style.css", /\/assets\//, '/images/'
42
+ end
43
+
44
+ ['markitup', 'simple'].each do |area|
45
+ gsub_file "public/stylesheets/markitup/skins/#{area}/style.css", /\/assets\//, '/images/'
46
+ end
47
+
48
+ gsub_file "public/stylesheets/jquery-ui.css", /\/assets\//, '/images/'
49
+ gsub_file "public/stylesheets/page_engine.css", /\/assets\//, '/images/'
50
+ end
51
+
52
+ def copy_javascripts
53
+ directory 'app/assets/javascripts', 'public/javascripts'
54
+ directory 'vendor/assets/javascripts', 'public/javascripts'
55
+ end
56
+
57
+ def copy_images
58
+ directory 'app/assets/images', 'public/images'
59
+ directory 'vendor/assets/images', 'public/images'
60
+ end
61
+
62
+ end
63
+ end
64
+ end if Rails.version < "3.1"
@@ -4,14 +4,18 @@ require 'page_engine/exceptions'
4
4
 
5
5
  class << ActionController::Base
6
6
  def page_engine(options = {})
7
+ # # Check options
8
+ # raise PageEngine::PageEngineException.new("Options for page_engine must be in a hash.") unless options.is_a? Hash
9
+ #
10
+ # options = {
11
+ # :layouts = ['application']
12
+ # }.merge(options)
7
13
 
8
- # Check options
9
- raise PageEngine::PageEngineException.new("Options for page_engine must be in a hash.") unless options.is_a? Hash
10
- options.each do |key, value|
11
- unless [:layouts].include?(key)
12
- raise PageEngine::PageEngineException.new("Unknown option for page_engine: #{key.inspect} => #{value.inspect}.")
13
- end
14
- end
14
+ # options.each do |key, value|
15
+ # unless [:layouts].include?(key)
16
+ # raise PageEngine::PageEngineException.new("Unknown option for page_engine: #{key.inspect} => #{value.inspect}.")
17
+ # end
18
+ # end
15
19
 
16
20
  include PageEngine::InstanceMethods
17
21
  extend PageEngine::ClassMethods
@@ -19,6 +23,6 @@ class << ActionController::Base
19
23
  before_filter :find_page
20
24
  layout :get_layout
21
25
 
22
- Page.layouts = options[:layouts].is_a?(Array) ? options[:layouts] : ['application']
26
+ # PageEngine.layouts = options[:layouts].is_a?(Array) ? options[:layouts] : ['application']
23
27
  end
24
28
  end
@@ -2,13 +2,13 @@ module PageEngine
2
2
  module InstanceMethods
3
3
  def get_layout
4
4
  if @page
5
- @page.layout.blank? ? Page.default_layout : @page.layout
5
+ @page.layout.blank? ? Page.default_layout.to_s : @page.layout.to_s
6
6
  else
7
- Page.default_layout
7
+ Page.default_layout.to_s
8
8
  end
9
9
  end
10
10
 
11
- def find_page permalink=nil
11
+ def find_page(permalink=nil)
12
12
  current_user = nil unless defined?(current_user)
13
13
 
14
14
  unless params[:controller].split('/').first == "admin"
@@ -23,7 +23,7 @@ module PageEngine
23
23
  end
24
24
  end
25
25
 
26
- def page_title_replace models=[]
26
+ def page_title_replace(models=[])
27
27
  models.each do |m|
28
28
  key = m.class.to_s.underscore
29
29
  @page.title.scan(/\{\{#{key}_([_a-z]*)\}\}/).uniq.flatten.each do |attribute|
@@ -43,7 +43,7 @@ module PageEngine
43
43
  end
44
44
  end
45
45
 
46
- def breadcrumb_replace models=[]
46
+ def breadcrumb_replace(models=[])
47
47
  models.each do |m|
48
48
  key = m.class.to_s.underscore
49
49
  @breadcrumbs.each do |breadcrumb|
@@ -72,7 +72,7 @@ module PageEngine
72
72
  def get_breadcrumbs
73
73
  current_user = nil unless defined?(current_user)
74
74
  if @page
75
- @breadcrumbs = @page.ancestors.published.viewable_by(current_user).all
75
+ @breadcrumbs = @page.ancestors.for_nav.published.viewable_by(current_user).all
76
76
  else
77
77
  @breadcrumbs = []
78
78
  end