page_engine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.markdown +74 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/images/page_engine/add.png +0 -0
  5. data/app/assets/images/page_engine/bullet_add.png +0 -0
  6. data/app/assets/images/page_engine/bullet_go.png +0 -0
  7. data/app/assets/images/page_engine/delete.png +0 -0
  8. data/app/assets/images/page_engine/page_add.png +0 -0
  9. data/app/assets/images/page_engine/page_copy.png +0 -0
  10. data/app/assets/images/page_engine/page_delete.png +0 -0
  11. data/app/assets/images/page_engine/page_edit.png +0 -0
  12. data/app/assets/images/page_engine/page_gear.png +0 -0
  13. data/app/assets/images/page_engine/page_green.png +0 -0
  14. data/app/assets/images/page_engine/page_hidden.png +0 -0
  15. data/app/assets/images/page_engine/page_lightning.png +0 -0
  16. data/app/assets/images/page_engine/page_line.jpg +0 -0
  17. data/app/assets/images/page_engine/page_red.png +0 -0
  18. data/app/assets/images/page_engine/pencil.png +0 -0
  19. data/app/assets/images/page_engine/waiting.gif +0 -0
  20. data/app/assets/images/page_engine/zoom.png +0 -0
  21. data/app/assets/javascripts/markitup/sets/css/set.js +52 -0
  22. data/app/assets/javascripts/markitup/sets/html/set.js +64 -0
  23. data/app/assets/javascripts/markitup/sets/javascript/set.js +6 -0
  24. data/app/assets/javascripts/markitup/sets/markdown/set.js +53 -0
  25. data/app/assets/javascripts/markitup/sets/textile/set.js +57 -0
  26. data/app/assets/javascripts/page_engine.js +189 -0
  27. data/app/assets/stylesheets/jquery-ui/smoothness/jquery-ui-1.8.15.custom.css +307 -0
  28. data/app/assets/stylesheets/markitup/sets/css/style.css +69 -0
  29. data/app/assets/stylesheets/markitup/sets/html/style.css +58 -0
  30. data/app/assets/stylesheets/markitup/sets/javascript/style.css +0 -0
  31. data/app/assets/stylesheets/markitup/sets/markdown/style.css +49 -0
  32. data/app/assets/stylesheets/markitup/sets/textile/style.css +58 -0
  33. data/app/assets/stylesheets/markitup/skins/markitup/style.css +147 -0
  34. data/app/assets/stylesheets/markitup/skins/simple/style.css +118 -0
  35. data/app/assets/stylesheets/page_engine.css +231 -0
  36. data/app/controllers/admin/page_snippets_controller.rb +64 -0
  37. data/app/controllers/admin/pages_controller.rb +167 -0
  38. data/app/controllers/pages_controller.rb +20 -0
  39. data/app/helpers/pages_helper.rb +234 -0
  40. data/app/models/page.rb +233 -0
  41. data/app/models/page_part.rb +35 -0
  42. data/app/models/page_role.rb +15 -0
  43. data/app/models/page_snippet.rb +30 -0
  44. data/app/views/admin/page_snippets/_form.html.haml +10 -0
  45. data/app/views/admin/page_snippets/destroy.js.erb +3 -0
  46. data/app/views/admin/page_snippets/edit.html.haml +6 -0
  47. data/app/views/admin/page_snippets/index.html.haml +20 -0
  48. data/app/views/admin/page_snippets/new.html.haml +6 -0
  49. data/app/views/admin/page_snippets/show.html.erb +20 -0
  50. data/app/views/admin/pages/_form.html.haml +56 -0
  51. data/app/views/admin/pages/_page.html.haml +19 -0
  52. data/app/views/admin/pages/_page_list.html.haml +2 -0
  53. data/app/views/admin/pages/_page_part_fields.html.haml +9 -0
  54. data/app/views/admin/pages/destroy.js.erb +1 -0
  55. data/app/views/admin/pages/duplicate.js.erb +5 -0
  56. data/app/views/admin/pages/edit.html.haml +9 -0
  57. data/app/views/admin/pages/index.html.haml +10 -0
  58. data/app/views/admin/pages/new.html.haml +10 -0
  59. data/app/views/admin/pages/show.html.erb +100 -0
  60. data/app/views/admin/pages/sort.js.erb +3 -0
  61. data/app/views/layouts/admin.html.haml +20 -0
  62. data/app/views/pages/_nav_item.html.haml +10 -0
  63. data/app/views/pages/_navigation.html.haml +11 -0
  64. data/app/views/pages/index.html.erb +2 -0
  65. data/app/views/pages/show.html.erb +2 -0
  66. data/config/routes.rb +23 -0
  67. data/db/migrate/20110814185929_create_page_engine.rb +77 -0
  68. data/db/seed.rb +8 -0
  69. data/lib/generators/page_engine/page_engine_generator.rb +59 -0
  70. data/lib/page_engine/class_methods.rb +4 -0
  71. data/lib/page_engine/defaults.rb +5 -0
  72. data/lib/page_engine/engine.rb +4 -0
  73. data/lib/page_engine/exceptions.rb +4 -0
  74. data/lib/page_engine/extensions.rb +24 -0
  75. data/lib/page_engine/helpers.rb +10 -0
  76. data/lib/page_engine/instance_methods.rb +82 -0
  77. data/lib/page_engine/routes_finder.rb +23 -0
  78. data/lib/page_engine.rb +41 -0
  79. data/lib/tasks/page_engine_tasks.rake +4 -0
  80. metadata +192 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
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.
data/README.markdown ADDED
@@ -0,0 +1,74 @@
1
+ # Page Engine
2
+
3
+ Page engine is a (_reasonably_) simple way to extend your rails application with pages. This allows you to automatically generate navigation, breadcrumbs and create page snippets to use anywhere in your app views.
4
+
5
+ ## Installation
6
+
7
+ For rails 3 and above simply add the following to your gemfile:
8
+
9
+ gem 'page_engine'
10
+
11
+ Then bundle install.
12
+
13
+ Since rails 3.0 doesn't support the asset pipeline out of the box you will also need to install the gems assets (images, css and javascript) using:
14
+
15
+ rails g page_engine
16
+
17
+ If you've managed to get the asset pipeline working in rails 3.0 then you can skip the above step... and feel free to give yourself a biscuit.
18
+
19
+ ## Usage
20
+
21
+ In application_controller add the line
22
+
23
+ page_engine
24
+
25
+ and you're good to go.
26
+
27
+ You can supply options to page engine, currently just the layouts that should be available to the pages, and you can do this using
28
+
29
+ page_engine { :layouts => ['application'] }
30
+
31
+ ## How it works
32
+
33
+ PageEngine comes with an admin namespace where you can CRUD your pages. It uses [jquery.nestedSortable](http://mjsarfatti.com/sandbox/nestedSortable/ "jquery.nestedSortable") to allow reordering and nesting of pages using drag and drop. When you create the page you can set a url or a controller and action and PageEngine use these to find the correct page. So, for example, say you have a welcome page at welcome#index, if you set the url to '/welcome' or choose welcome#index from the dropdown that page record will be retrieved when the welcome index page is hit and be available to your views.
34
+
35
+ Using [MarkItUp](http://markitup.jaysalvat.com/home/ "MarkItUp") it's possible to write page content using textile, markdown or plain html. There's also the option to use erb but this is pretty dangerous and open to abuse so don't count on it being in there forever.
36
+
37
+ ## In the views
38
+
39
+ PageEngine comes with a few helpers:
40
+
41
+ navigation(root page permalink, options)
42
+
43
+ This generates an unordered list (ul) containing the root page and it's descendants up to the depth specified in the options.
44
+
45
+ page_content
46
+
47
+ Renders the page content using the filter specified (textile, markdown etc). Defaults to using the automatically found page and it's body page part but this can be overriden in the options
48
+
49
+ breadcrumbs
50
+
51
+ Generates a set of links that represent the current page and it's ancestors
52
+
53
+ page_title
54
+
55
+
56
+ page_js
57
+
58
+
59
+ page_css
60
+
61
+
62
+ page_meta_keywords
63
+
64
+
65
+ page_meta_description
66
+
67
+
68
+ page_snippet snippet name
69
+
70
+ Renders the named snippet
71
+
72
+ ## Rails engine
73
+
74
+ Since this was built using the rails 3.1 plugin generator you can test the gem using the dummy application which can be found under spec/dummy.
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'PageEngine'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+
39
+ task :default => :test
@@ -0,0 +1,52 @@
1
+ // ----------------------------------------------------------------------------
2
+ // markItUp!
3
+ // ----------------------------------------------------------------------------
4
+ // Copyright (C) 2008 Jay Salvat
5
+ // http://markitup.jaysalvat.com/
6
+ // ----------------------------------------------------------------------------
7
+ // CSS set by Kevin Papst
8
+ // http://www.kevinpapst.de/
9
+ // Initially written for the BIGACE CMS:
10
+ // http://www.bigace.de/
11
+ // ----------------------------------------------------------------------------
12
+ // Basic CSS set. Feel free to add more tags
13
+ // ----------------------------------------------------------------------------
14
+ markitup_css_settings = {
15
+ onEnter: {},
16
+ onShiftEnter: {keepDefault:false, placeHolder:'Your comment here', openWith:'\n\/* ', closeWith:' *\/'},
17
+ onCtrlEnter: {keepDefault:false, placeHolder:"classname", openWith:'\n.', closeWith:' { \n'},
18
+ onTab: {keepDefault:false, openWith:' '},
19
+ markupSet: [
20
+ {name:'Class', className:'class', key:'N', placeHolder:'Properties here...', openWith:'.[![Class name]!] {\n', closeWith:'\n}'},
21
+ {separator:'---------------' },
22
+ {name:'Bold', className:'bold', key:'B', replaceWith:'font-weight:bold;'},
23
+ {name:'Italic', className:'italic', key:'I', replaceWith:'font-style:italic;'},
24
+ {name:'Stroke through', className:'stroke', key:'S', replaceWith:'text-decoration:line-through;'},
25
+ {separator:'---------------' },
26
+ {name:'Lowercase', className:'lowercase', key:'L', replaceWith:'text-transform:lowercase;'},
27
+ {name:'Uppercase', className:'uppercase', key:'U', replaceWith:'text-transform:uppercase;'},
28
+ {separator:'---------------' },
29
+ {name:'Text indent', className:'indent', openWith:'text-indent:', placeHolder:'5px', closeWith:';' },
30
+ {name:'Letter spacing', className:'letterspacing', openWith:'letter-spacing:', placeHolder:'5px', closeWith:';' },
31
+ {name:'Line height', className:'lineheight', openWith:'line-height:', placeHolder:'1.5', closeWith:';' },
32
+ {separator:'---------------' },
33
+ {name:'Alignments', className:'alignments', dropMenu:[
34
+ {name:'Left', className:'left', replaceWith:'text-align:left;'},
35
+ {name:'Center', className:'center', replaceWith:'text-align:center;'},
36
+ {name:'Right', className:'right', replaceWith:'text-align:right;'},
37
+ {name:'Justify', className:'justify', replaceWith:'text-align:justify;'}
38
+ ]
39
+ },
40
+ {name:'Padding/Margin', className:'padding', dropMenu:[
41
+ {name:'Top', className:'top', openWith:'(!(padding|!|margin)!)-top:', placeHolder:'5px', closeWith:';' },
42
+ {name:'Left', className:'left', openWith:'(!(padding|!|margin)!)-left:', placeHolder:'5px', closeWith:';' },
43
+ {name:'Right', className:'right', openWith:'(!(padding|!|margin)!)-right:', placeHolder:'5px', closeWith:';' },
44
+ {name:'Bottom', className:'bottom', openWith:'(!(padding|!|margin)!)-bottom:', placeHolder:'5px', closeWith:';' }
45
+ ]
46
+ },
47
+ {separator:'---------------' },
48
+ {name:'Background Image', className:'background', replaceWith:'background:url([![Source:!:http://]!]) no-repeat 0 0;' },
49
+ {separator:'---------------' },
50
+ {name:'Import CSS file', className:'css', replaceWith:'@import "[![Source file:!:.css]!]";' }
51
+ ]
52
+ }
@@ -0,0 +1,64 @@
1
+ // ----------------------------------------------------------------------------
2
+ // markItUp!
3
+ // ----------------------------------------------------------------------------
4
+ // Copyright (C) 2008 Jay Salvat
5
+ // http://markitup.jaysalvat.com/
6
+ // ----------------------------------------------------------------------------
7
+ // Html tags
8
+ // http://en.wikipedia.org/wiki/html
9
+ // ----------------------------------------------------------------------------
10
+ // Basic set. Feel free to add more tags
11
+ // ----------------------------------------------------------------------------
12
+ markitup_html_settings = {
13
+ previewTemplatePath: '/assets/markitup/templates/preview.html',
14
+ onShiftEnter: {keepDefault:false, replaceWith:'<br />\n'},
15
+ onCtrlEnter: {keepDefault:false, openWith:'\n<p>', closeWith:'</p>\n'},
16
+ onTab: {keepDefault:false, openWith:' '},
17
+ markupSet: [
18
+ {name:'Heading 1', key:'1', openWith:'<h1(!( class="[![Class]!]")!)>', closeWith:'</h1>', placeHolder:'Your title here...' },
19
+ {name:'Heading 2', key:'2', openWith:'<h2(!( class="[![Class]!]")!)>', closeWith:'</h2>', placeHolder:'Your title here...' },
20
+ {name:'Heading 3', key:'3', openWith:'<h3(!( class="[![Class]!]")!)>', closeWith:'</h3>', placeHolder:'Your title here...' },
21
+ {name:'Heading 4', key:'4', openWith:'<h4(!( class="[![Class]!]")!)>', closeWith:'</h4>', placeHolder:'Your title here...' },
22
+ {name:'Heading 5', key:'5', openWith:'<h5(!( class="[![Class]!]")!)>', closeWith:'</h5>', placeHolder:'Your title here...' },
23
+ {name:'Heading 6', key:'6', openWith:'<h6(!( class="[![Class]!]")!)>', closeWith:'</h6>', placeHolder:'Your title here...' },
24
+ {name:'Paragraph', openWith:'<p(!( class="[![Class]!]")!)>', closeWith:'</p>' },
25
+ {separator:'---------------' },
26
+ {name:'Bold', key:'B', openWith:'(!(<strong>|!|<b>)!)', closeWith:'(!(</strong>|!|</b>)!)' },
27
+ {name:'Italic', key:'I', openWith:'(!(<em>|!|<i>)!)', closeWith:'(!(</em>|!|</i>)!)' },
28
+ {name:'Stroke through', key:'S', openWith:'<del>', closeWith:'</del>' },
29
+ {separator:'---------------' },
30
+ {name:'Ul', openWith:'<ul>\n', closeWith:'</ul>\n' },
31
+ {name:'Ol', openWith:'<ol>\n', closeWith:'</ol>\n' },
32
+ {name:'Li', openWith:'<li>', closeWith:'</li>' },
33
+ {separator:'---------------' },
34
+ {name:'Picture', key:'P', replaceWith:'<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />' },
35
+ {name:'Link', key:'L', openWith:'<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>', closeWith:'</a>', placeHolder:'Your text to link...' },
36
+ {separator:'---------------' },
37
+ {name:'Clean', className:'clean', replaceWith:function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") } },
38
+ {name:'Preview', className:'preview', call:'preview' },{ name:'Table generator',
39
+ className:'tablegenerator',
40
+ placeholder:"Your text here...",
41
+ replaceWith:function(markItUp) {
42
+ var cols = prompt("How many cols?"),
43
+ rows = prompt("How many rows?"),
44
+ html = "<table>\n";
45
+ if (markItUp.altKey) {
46
+ html += " <tr>\n";
47
+ for (var c = 0; c < cols; c++) {
48
+ html += "! [![TH"+(c+1)+" text:]!]\n";
49
+ }
50
+ html+= " </tr>\n";
51
+ }
52
+ for (var r = 0; r < rows; r++) {
53
+ html+= " <tr>\n";
54
+ for (var c = 0; c < cols; c++) {
55
+ html += " <td>"+(markItUp.placeholder||"")+"</td>\n";
56
+ }
57
+ html+= " </tr>\n";
58
+ }
59
+ html += "<table>\n";
60
+ return html;
61
+ }
62
+ }
63
+ ]
64
+ }
@@ -0,0 +1,6 @@
1
+ markitup_javascript_settings = {
2
+ onEnter: {},
3
+ onShiftEnter: {keepDefault:false, placeHolder:'Your comment here', openWith:'\n\\\\ '},
4
+ onTab: {keepDefault:false, openWith:' '},
5
+ markupSet: []
6
+ }
@@ -0,0 +1,53 @@
1
+ // -------------------------------------------------------------------
2
+ // markItUp!
3
+ // -------------------------------------------------------------------
4
+ // Copyright (C) 2008 Jay Salvat
5
+ // http://markitup.jaysalvat.com/
6
+ // -------------------------------------------------------------------
7
+ // MarkDown tags example
8
+ // http://en.wikipedia.org/wiki/Markdown
9
+ // http://daringfireball.net/projects/markdown/
10
+ // -------------------------------------------------------------------
11
+ // Feel free to add more tags
12
+ // -------------------------------------------------------------------
13
+ markitup_markdown_settings = {
14
+ previewTemplatePath: '/assets/markitup/templates/preview.html',
15
+ previewParserPath: '/admin/pages/parse_content?data_type=markdown', // path to your Textile parser
16
+ onShiftEnter: {keepDefault:false, openWith:'\n\n'},
17
+ markupSet: [
18
+ {name:'First Level Heading', key:'1', placeHolder:'Your title here...', closeWith:function(markItUp) { return miu.markdownTitle(markItUp, '=') } },
19
+ {name:'Second Level Heading', key:'2', placeHolder:'Your title here...', closeWith:function(markItUp) { return miu.markdownTitle(markItUp, '-') } },
20
+ {name:'Heading 3', key:'3', openWith:'### ', placeHolder:'Your title here...' },
21
+ {name:'Heading 4', key:'4', openWith:'#### ', placeHolder:'Your title here...' },
22
+ {name:'Heading 5', key:'5', openWith:'##### ', placeHolder:'Your title here...' },
23
+ {name:'Heading 6', key:'6', openWith:'###### ', placeHolder:'Your title here...' },
24
+ {separator:'---------------' },
25
+ {name:'Bold', key:'B', openWith:'**', closeWith:'**'},
26
+ {name:'Italic', key:'I', openWith:'_', closeWith:'_'},
27
+ {separator:'---------------' },
28
+ {name:'Bulleted List', openWith:'- ' },
29
+ {name:'Numeric List', openWith:function(markItUp) {
30
+ return markItUp.line+'. ';
31
+ }},
32
+ {separator:'---------------' },
33
+ {name:'Picture', key:'P', replaceWith:'![[![Alternative text]!]]([![Url:!:http://]!] "[![Title]!]")'},
34
+ {name:'Link', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!] "[![Title]!]")', placeHolder:'Your text to link here...' },
35
+ {separator:'---------------'},
36
+ {name:'Quotes', openWith:'> '},
37
+ {name:'Code Block / Code', openWith:'(!(\t|!|`)!)', closeWith:'(!(`)!)'},
38
+ {separator:'---------------'},
39
+ {name:'Preview', call:'preview', className:"preview"}
40
+ ]
41
+ }
42
+
43
+ // mIu nameSpace to avoid conflict.
44
+ miu = {
45
+ markdownTitle: function(markItUp, char) {
46
+ heading = '';
47
+ n = $.trim(markItUp.selection||markItUp.placeHolder).length;
48
+ for(i = 0; i < n; i++) {
49
+ heading += char;
50
+ }
51
+ return '\n'+heading;
52
+ }
53
+ }
@@ -0,0 +1,57 @@
1
+ // -------------------------------------------------------------------
2
+ // markItUp!
3
+ // -------------------------------------------------------------------
4
+ // Copyright (C) 2008 Jay Salvat
5
+ // http://markitup.jaysalvat.com/
6
+ // -------------------------------------------------------------------
7
+ // Textile tags example
8
+ // http://en.wikipedia.org/wiki/Textile_(markup_language)
9
+ // http://www.textism.com/
10
+ // -------------------------------------------------------------------
11
+ // Feel free to add more tags
12
+ // -------------------------------------------------------------------
13
+ markitup_textile_settings = {
14
+ previewTemplatePath: '/assets/markitup/templates/preview.html',
15
+ previewParserPath: '/admin/pages/parse_content?data_type=textile', // path to your Textile parser
16
+ onShiftEnter: {keepDefault:false, replaceWith:'\n\n'},
17
+ markupSet: [
18
+ {name:'Heading 1', key:'1', openWith:'h1(!(([![Class]!]))!). ', placeHolder:'Your title here...' },
19
+ {name:'Heading 2', key:'2', openWith:'h2(!(([![Class]!]))!). ', placeHolder:'Your title here...' },
20
+ {name:'Heading 3', key:'3', openWith:'h3(!(([![Class]!]))!). ', placeHolder:'Your title here...' },
21
+ {name:'Heading 4', key:'4', openWith:'h4(!(([![Class]!]))!). ', placeHolder:'Your title here...' },
22
+ {name:'Heading 5', key:'5', openWith:'h5(!(([![Class]!]))!). ', placeHolder:'Your title here...' },
23
+ {name:'Heading 6', key:'6', openWith:'h6(!(([![Class]!]))!). ', placeHolder:'Your title here...' },
24
+ {name:'Paragraph', key:'P', openWith:'p(!(([![Class]!]))!). '},
25
+ {separator:'---------------' },
26
+ {name:'Bold', key:'B', closeWith:'*', openWith:'*'},
27
+ {name:'Italic', key:'I', closeWith:'_', openWith:'_'},
28
+ {name:'Stroke through', key:'S', closeWith:'-', openWith:'-'},
29
+ {separator:'---------------' },
30
+ {name:'Bulleted list', openWith:'(!(* |!|*)!)'},
31
+ {name:'Numeric list', openWith:'(!(# |!|#)!)'},
32
+ {separator:'---------------' },
33
+ {name:'Picture', replaceWith:'![![Source:!:http://]!]([![Alternative text]!])!'},
34
+ {name:'Link', openWith:'"', closeWith:'([![Title]!])":[![Link:!:http://]!]', placeHolder:'Your text to link here...' },
35
+ {separator:'---------------' },
36
+ {name:'Quotes', openWith:'bq(!(([![Class]!]))!). '},
37
+ {name:'Code', openWith:'@', closeWith:'@'},
38
+ {separator:'---------------' },
39
+ {name:'Preview', call:'preview', className:'preview'},
40
+ {name:'Table generator',
41
+ className:'tablegenerator',
42
+ placeholder:"Your text here...",
43
+ replaceWith:function(h) {
44
+ cols = prompt("How many cols?");
45
+ rows = prompt("How many rows?");
46
+ html = "";
47
+ for (r = 0; r < rows; r++) {
48
+ for (c = 0; c < cols; c++) {
49
+ html += "|"+(h.placeholder||"");
50
+ }
51
+ html += "|\n";
52
+ }
53
+ return html;
54
+ }
55
+ }
56
+ ]
57
+ }
@@ -0,0 +1,189 @@
1
+ //= require jquery-ui-1.8.15.custom.min
2
+ //= require jquery.markitup
3
+ //= require markitup/sets/html/set
4
+ //= require markitup/sets/textile/set
5
+ //= require markitup/sets/markdown/set
6
+ //= require markitup/sets/css/set
7
+ //= require markitup/sets/javascript/set
8
+ //= require jquery.ui.nestedSortable
9
+
10
+ $(document).ready(function(){
11
+
12
+ $('ol#page_engine').nestedSortable({
13
+ disableNesting: 'no-nest',
14
+ forcePlaceholderSize: true,
15
+ handle: 'div',
16
+ helper: 'clone',
17
+ items: 'li',
18
+ opacity: .6,
19
+ placeholder: 'placeholder',
20
+ revert: 250,
21
+ tabSize: 25,
22
+ tolerance: 'pointer',
23
+ toleranceElement: '> div'
24
+ });
25
+
26
+ $('#update_page_positions').click(function(){
27
+ page_array = $('ol#page_engine').nestedSortable('toArray', { startDepthCount: 0 });
28
+ page_array.splice(0, 1);
29
+
30
+ $.ajax({
31
+ data: { pages: page_array },
32
+ dataType:'script',
33
+ url: $('ol#page_engine').attr('data-href'),
34
+ type: 'put'
35
+ });
36
+ return false;
37
+ });
38
+
39
+ var selected_tab = 0;
40
+ var page_parts = $('.page_parts').tabs({
41
+ select: function(event, ui){
42
+ selected_tab = ui.index;
43
+ }
44
+ });
45
+
46
+ $('.page_part a.delete').live('click', function(){
47
+ $(this).prev().val(true);
48
+ $('.page_parts').after($(this).prev());
49
+ page_parts.tabs('remove', selected_tab);
50
+ return false;
51
+ });
52
+
53
+ $('textarea[data-filter=css]').each(function(){
54
+ add_css($(this));
55
+ });
56
+
57
+ $('textarea[data-filter=javascript]').each(function(){
58
+ add_javascript($(this));
59
+ });
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
+
105
+ $('#page_no_publish_window').change(function(){
106
+ $('.edit_page .field.publish_from').toggle('slide');
107
+ $('.edit_page .field.publish_to').toggle('slide');
108
+ });
109
+
110
+ $('textarea.ignore_tab').keypress(function(e){
111
+ if(e.keyCode == 9){
112
+ var pos = $(this).caret().start + 2;
113
+ text = $(this).val().substr(0, $(this).caret().start) + ' ' + $(this).val().substr($(this).caret().start);
114
+ console.debug($(this).val().substr($(this).caret().start));
115
+ $(this).val(text);
116
+
117
+ if ($(this).get(0).setSelectionRange)
118
+ {
119
+ $(this).get(0).setSelectionRange(pos, pos);
120
+ }
121
+ else if ($(this).get(0).createTextRange)
122
+ {
123
+ var range = $(this).get(0).createTextRange();
124
+ range.collapse(true); range.moveEnd("character", pos);
125
+ range.moveStart("character", pos); range.select();
126
+ }
127
+ return false;
128
+ }
129
+ });
130
+ });
131
+
132
+ add_html = function(textarea){
133
+ remove_editors(textarea);
134
+ textarea.markItUp(markitup_html_settings);
135
+ textarea.parents('.markItUp').addClass('html');
136
+ }
137
+
138
+ add_textile = function(textarea){
139
+ remove_editors(textarea);
140
+ textarea.markItUp(markitup_textile_settings);
141
+ textarea.parents('.markItUp').addClass('textile');
142
+ }
143
+
144
+ add_markdown = function(textarea){
145
+ remove_editors(textarea);
146
+ textarea.markItUp(markitup_markdown_settings);
147
+ textarea.parents('.markItUp').addClass('markdown');
148
+ }
149
+
150
+ add_css = function(textarea){
151
+ remove_editors(textarea);
152
+ textarea.markItUp(markitup_css_settings);
153
+ textarea.parents('.markItUp').addClass('css');
154
+ }
155
+
156
+ add_javascript = function(textarea){
157
+ remove_editors(textarea);
158
+ textarea.markItUp(markitup_javascript_settings);
159
+ textarea.parents('.markItUp').addClass('javascript');
160
+ }
161
+
162
+ remove_editors = function(textarea){
163
+ textarea.markItUpRemove();
164
+ }
165
+
166
+ add_fields = function(link, association, content){
167
+ var page_part_name = $('#new_page_part_name').val();
168
+
169
+ if (page_part_name != ''){
170
+ if ($('#' + page_part_name.replace(/[^a-z0-9\-_]+/ig, '-')).length == 0){
171
+ var new_id = new Date().getTime();
172
+
173
+ content = content.replace(/name="page_parts/g, 'name="page[page_parts_attributes][' + new_id + ']');
174
+ content = content.replace(/for="page_parts/g, 'for="page_page_parts_attributes_' + new_id);
175
+
176
+ $('.page_parts').tabs('add', '#' + new_id, page_part_name);
177
+ $('#' + new_id).html(content);
178
+ $('#' + new_id).addClass('page_part');
179
+ $('#' + new_id + ' .input:first input').val(page_part_name);
180
+ $('#new_page_part_name').val('');
181
+ }
182
+ else {
183
+ alert('Name already exists');
184
+ }
185
+ } else {
186
+ alert('You need to specify a name');
187
+ }
188
+ }
189
+