jakewendt-simply_pages 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. data/README.rdoc +65 -0
  2. data/generators/simply_pages/USAGE +0 -0
  3. data/generators/simply_pages/simply_pages_generator.rb +120 -0
  4. data/generators/simply_pages/templates/autotest_simply_pages.rb +2 -0
  5. data/generators/simply_pages/templates/controllers/locales_controller.rb +16 -0
  6. data/generators/simply_pages/templates/controllers/pages_controller.rb +160 -0
  7. data/generators/simply_pages/templates/functional/locales_controller_test.rb +58 -0
  8. data/generators/simply_pages/templates/functional/pages_controller_test.rb +237 -0
  9. data/generators/simply_pages/templates/images/drag.gif +0 -0
  10. data/generators/simply_pages/templates/javascripts/pages.js +48 -0
  11. data/generators/simply_pages/templates/migrations/create_pages.rb +26 -0
  12. data/generators/simply_pages/templates/models/page.rb +107 -0
  13. data/generators/simply_pages/templates/models/page_sweeper.rb +74 -0
  14. data/generators/simply_pages/templates/simply_pages.rake +5 -0
  15. data/generators/simply_pages/templates/stylesheets/page.css +17 -0
  16. data/generators/simply_pages/templates/stylesheets/pages.css +22 -0
  17. data/generators/simply_pages/templates/unit/page_test.rb +149 -0
  18. data/generators/simply_pages/templates/unit/redcloth_extension_test.rb +64 -0
  19. data/generators/simply_pages/templates/views/pages/_child.html.erb +20 -0
  20. data/generators/simply_pages/templates/views/pages/_form.html.erb +44 -0
  21. data/generators/simply_pages/templates/views/pages/_page.html.erb +34 -0
  22. data/generators/simply_pages/templates/views/pages/all.html.erb +39 -0
  23. data/generators/simply_pages/templates/views/pages/edit.html.erb +10 -0
  24. data/generators/simply_pages/templates/views/pages/index.html.erb +29 -0
  25. data/generators/simply_pages/templates/views/pages/new.html.erb +10 -0
  26. data/generators/simply_pages/templates/views/pages/show.html.erb +31 -0
  27. data/generators/simply_pages/templates/views/pages/translate.js.erb +42 -0
  28. metadata +93 -0
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+
3
+ class RedClothExtensionTest < ActiveSupport::TestCase
4
+
5
+ teardown :destroy_relative_url_root
6
+
7
+ test "should NOT add relative url root to link when blank" do
8
+ html = textilize('"Link Text":/link/path')
9
+ #=> "<p><a href=\"/link/path\">Link Text</a></p>"
10
+ assert_match(/a href="\/link\/path"/,html)
11
+ end
12
+
13
+ test "should add relative url root to link when not blank" do
14
+ ActionController::Base.relative_url_root = "/prefix"
15
+ html = textilize('"Link Text":/link/path')
16
+ #=> "<p><a href=\"/prefix/link/path\">Link Text</a></p>"
17
+ assert_match(/a href="\/prefix\/link\/path"/,html)
18
+ end
19
+
20
+ test "should NOT add relative url root to image href when blank" do
21
+ html = textilize('!/path/to/image.jpg!:/link/path')
22
+ #=> "<p><a href=\"/link/path\">
23
+ # <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
24
+ assert_match(/a href="\/link\/path"/,html)
25
+ end
26
+
27
+ test "should add relative url root to image href when not blank" do
28
+ ActionController::Base.relative_url_root = "/prefix"
29
+ html = textilize('!/path/to/image.jpg!:/link/path')
30
+ #=> "<p><a href=\"/link/path\">
31
+ # <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
32
+ assert_match(/a href="\/prefix\/link\/path"/,html)
33
+ end
34
+
35
+ test "should NOT add relative url root to image src when blank" do
36
+ html = textilize('!/path/to/image.jpg!:/link/path')
37
+ #=> "<p><a href=\"/link/path\">
38
+ # <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
39
+ assert_match(/img src="\/path\/to\/image\.jpg"/,html)
40
+ end
41
+
42
+ test "should add relative url root to image src when not blank" do
43
+ ActionController::Base.relative_url_root = "/prefix"
44
+ html = textilize('!/path/to/image.jpg!:/link/path')
45
+ #=> "<p><a href=\"/link/path\">
46
+ # <img src=\"/path/to/image.jpg\" alt=\"\" /></a></p>"
47
+ assert_match(/img src="\/prefix\/path\/to\/image\.jpg"/,html)
48
+ end
49
+
50
+
51
+ # Add tests for when
52
+ # relative_url_root is nil
53
+ # paths are absolute
54
+ # paths are relative to current location ('../......')
55
+ # there is no path, just the file
56
+
57
+
58
+ protected
59
+
60
+ def destroy_relative_url_root
61
+ ActionController::Base.relative_url_root = nil #''
62
+ end
63
+
64
+ end
@@ -0,0 +1,20 @@
1
+ <% content_tag_for( :tr, child ) do %>
2
+ <td class='path'>
3
+ <%= link_to child.path, child.path -%>
4
+ </td>
5
+ <td class='menu'>
6
+ <%= link_to child.menu(session[:locale]), child -%>
7
+ </td>
8
+ <td class='title'>
9
+ <%= link_to child.title(session[:locale]), child -%>
10
+ </td>
11
+ <td class='manage'>
12
+ <%= link_to "Edit", edit_page_path(child), :class => 'button' -%>
13
+ &nbsp;
14
+ <% destroy_link_to "Destroy", page_path(child) do %>
15
+ <%= hidden_field_tag 'confirm', "Destroy page '#{child}'?",
16
+ :id => nil %>
17
+ <%= submit_link_to 'Destroy' %>
18
+ <% end %>
19
+ </td>
20
+ <% end %><!-- class='child' -->
@@ -0,0 +1,44 @@
1
+ <% stylesheets('page') %>
2
+
3
+ <fieldset id='page'>
4
+ <legend>Page</legend>
5
+
6
+ <div class='parent'>
7
+ <b>Parent?</b> (Is this a main or sub menu page?)<br/>
8
+ <%= f.collection_select :parent_id, Page.all(:order => "menu_en"),
9
+ :id, :menu, :include_blank => true %>
10
+ </div>
11
+
12
+ <div class='hide_menu'>
13
+ <br/>
14
+ <%= f.check_box :hide_menu %>
15
+ <%= f.label :hide_menu, "Hide in menu system" %>
16
+ </div>
17
+
18
+ <div class='fields'>
19
+
20
+ <p><b>Path:</b> (this is the path in the url. ie. /help/login )</p>
21
+ <%= f.text_field :path %>
22
+
23
+ <p><b>Title</b> (this is the text on the top of the browser)</p>
24
+ English:<%= f.text_field :title_en %>
25
+ Spanish:<%= f.text_field :title_es %>
26
+
27
+ <p><b>Menu</b> (this is the text on the menu)</p>
28
+ English:<%= f.text_field :menu_en %>
29
+ Spanish:<%= f.text_field :menu_es %>
30
+
31
+ <p><b>Body</b> (uses sanitized <%= link_to 'textile', 'http://redcloth.org', :target => 'new' %>)</p>
32
+ English:<%= f.text_area :body_en %>
33
+ Spanish:<%= f.text_area :body_es %>
34
+ </div><!-- fields -->
35
+
36
+ <p class='note'>
37
+ For special characters, like &ntilde;, &oacute;, &eacute;, etc., use the 'friendly code' from
38
+ <%= link_to "About.com", "http://webdesign.about.com/library/bl_htmlcodes.htm", :target => 'new' %>
39
+ or 'Entity Name' from
40
+ <%= link_to "W3Schools.com", "http://www.w3schools.com/tags/ref_entities.asp", :target => 'new' %>.
41
+ The 'Numerical Code', 'Hex Code' or 'Entity Number' work just as well, but aren't as clear.
42
+ </p>
43
+
44
+ </fieldset>
@@ -0,0 +1,34 @@
1
+ <% content_tag_for( :tr, page, :class => 'row' ) do %>
2
+ <td><%= hidden_field_tag( 'pages[]', page.id, :id => nil ) %>
3
+ <%= image_tag 'drag.gif', :class => 'handle' %></td>
4
+ <td class='position'><%= page.position -%></td>
5
+
6
+ <td><table><tbody><tr>
7
+ <td class='path'>
8
+ <%= link_to page.path,
9
+ ActionController::Base.relative_url_root.to_s + page.path -%>
10
+ </td>
11
+ <td class='menu'>
12
+ <%= link_to page.menu(session[:locale]), page -%>
13
+ </td>
14
+ <td class='title'>
15
+ <%= link_to page.title(session[:locale]), page -%>
16
+ </td>
17
+ <td class='manage'>
18
+ <% if page.children.length > 1 %>
19
+ <%= link_to "Order", pages_path(:parent_id => page.id), :class => 'button' -%>&nbsp;
20
+ <% end %>
21
+ <%= link_to "Edit", edit_page_path(page), :class => 'button' -%>&nbsp;
22
+ <% destroy_link_to "Destroy", page_path(page) do %>
23
+ <%= hidden_field_tag 'confirm', "Destroy page '#{page}'?",
24
+ :id => nil %>
25
+ <%= submit_link_to 'Destroy' %>
26
+ <% end %>
27
+ </td>
28
+ </tr>
29
+
30
+ <% if page.children.length > 0 %>
31
+ <%= render :partial => 'child', :collection => page.children %>
32
+ <% end %>
33
+ </tbody></table></td>
34
+ <% end %><!-- class='page' -->
@@ -0,0 +1,39 @@
1
+ <% javascripts('pages') %>
2
+ <% stylesheets('pages') %>
3
+
4
+ <h4>All Pages:</h4>
5
+ <% unless @pages.empty? %>
6
+ <table id='pages'><thead>
7
+ <tr>
8
+ <th>Path</th>
9
+ <th>Menu</th>
10
+ <th>Title</th>
11
+ <th>&nbsp;</th>
12
+ </tr>
13
+ </thead><tbody>
14
+ <% @pages.each do |page| %>
15
+ <% content_tag_for( :tr, page, :class => 'row' ) do %>
16
+ <td class='path'>
17
+ <%= link_to page.path,
18
+ ActionController::Base.relative_url_root.to_s + page.path -%>
19
+ </td>
20
+ <td class='menu'>
21
+ <%= link_to page.menu(session[:locale]), page -%>
22
+ </td>
23
+ <td class='title'>
24
+ <%= link_to page.title(session[:locale]), page -%>
25
+ </td>
26
+ <td class='manage'>
27
+ <%= link_to "Edit", edit_page_path(page), :class => 'button' -%>&nbsp;
28
+ <% destroy_link_to "Destroy", page_path(page) do %>
29
+ <%= hidden_field_tag 'confirm', "Destroy page '#{page}'?",
30
+ :id => nil %>
31
+ <%= submit_link_to 'Destroy' %>
32
+ <% end %>
33
+ </td>
34
+ <% end %><%# tr %>
35
+ <% end %><%# pages.each %>
36
+ </tbody></table><!-- id='pages' -->
37
+ <% else %>
38
+ <p>Sorry, no pages yet.</p>
39
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%= error_messages_for :page %>
2
+
3
+ <% form_for(@page) do |f| %>
4
+ <%= render 'form', :f => f %>
5
+ <p>
6
+ <%= f.submit "Update", :id => nil %>&nbsp;
7
+ <%= submit_link_to 'Update' %>
8
+ <%= link_to "Cancel and View", @page, :class => 'button' %>
9
+ </p>
10
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <% javascripts('pages') %>
2
+ <% stylesheets('pages') %>
3
+
4
+ <h4>Pages:</h4>
5
+ <% unless @pages.empty? %>
6
+ <table id='pages'><tbody>
7
+ <%= render :partial => 'page', :collection => @pages %>
8
+ </tbody></table><!-- id='pages' -->
9
+ <% else %>
10
+ <p>Sorry, no pages yet.</p>
11
+ <% end %><%# unless @pages.empty? %>
12
+
13
+ <% form_tag(order_pages_path, :method => :post, :id => 'order_pages') do -%>
14
+ <%= hidden_field_tag :parent_id, params[:parent_id] %>
15
+ <p>
16
+ <%= link_to "View all pages", all_pages_path, :class => 'button' -%>&nbsp;
17
+ <%= link_to "Create new page",
18
+ new_page_path(:parent_id => params[:parent_id]),
19
+ :class => 'button' -%>&nbsp;
20
+ <%= submit_tag 'Save page order', :name => nil, :id => 'save_order' %>
21
+ </p>
22
+ <% end %>
23
+ <p>
24
+ The page model is used as a Content Management System
25
+ and for menu control. Some routes are not available
26
+ because the application is using them, but in order to
27
+ have the menu function, a "fake page" is created as a
28
+ placeholder. The staff functionality is an example.
29
+ </p>
@@ -0,0 +1,10 @@
1
+ <%= error_messages_for :page %>
2
+
3
+ <% form_for(@page) do |f| %>
4
+ <%= render 'form', :f => f %>
5
+ <p>
6
+ <%= f.submit "Create", :id => nil %>&nbsp;
7
+ <%= submit_link_to "Create" %>
8
+ <%= link_to "Cancel", pages_path, :class => 'button' %>
9
+ </p>
10
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <% if @page -%>
2
+ <% content_for :head do -%>
3
+ <% javascript_tag do -%>
4
+ if ( typeof(translatables) == 'undefined' ){
5
+ var translatables = [];
6
+ }
7
+ tmp = { tag: '#page', locales: {} };
8
+ <% %w( en es ).each do |locale| -%>
9
+ tmp.locales["<%=locale%>"]="<%=URI.encode(sanitize(textilize(@page.body(locale))))-%>"
10
+ <% end -%>
11
+ translatables.push(tmp);
12
+
13
+ tmp = { tag: 'title', locales: {} };
14
+ <% %w( en es ).each do |locale| -%>
15
+ tmp.locales["<%=locale%>"]="<%=URI.encode(@page.title(locale))-%>"
16
+ <% end -%>
17
+ translatables.push(tmp);
18
+
19
+ tmp = { tag: '#current_root', locales: {} };
20
+ <% %w( en es ).each do |locale| -%>
21
+ tmp.locales["<%=locale%>"]="<%=URI.encode(@page.menu(locale))-%>"
22
+ <% end -%>
23
+ translatables.push(tmp);
24
+ <% end ; end ; end -%>
25
+
26
+ <%# The above isn't really used anymore and I should destroy it %>
27
+ <div id='page'>
28
+ <% if @page -%>
29
+ <%= sanitize(textilize(@page.body(session[:locale]))) -%>
30
+ <% end -%>
31
+ </div>
@@ -0,0 +1,42 @@
1
+ jQuery(function(){
2
+
3
+ locale = '<%=session[:locale] || 'en'%>'
4
+
5
+ set_locale_link = function(l){
6
+ if( l == 'es' ){
7
+ locale_link = '<%=link_to( 'English',
8
+ locale_path('en'),
9
+ :id => 'session_locale' )-%>'
10
+ }else{
11
+ locale_link = '<%=link_to( 'Espa&ntilde;ol',
12
+ locale_path('es'),
13
+ :id => 'session_locale' )-%>'
14
+ }
15
+
16
+ jQuery('#session_locale').replaceWith(locale_link);
17
+
18
+ jQuery('#session_locale').click(function(){
19
+ jQuery.getScript(this.href, function(){
20
+ translate(locale);
21
+ set_locale_link(locale);
22
+ });
23
+ return false;
24
+ });
25
+ }
26
+ set_locale_link(locale);
27
+
28
+ translate = function(l){
29
+ if( typeof(translatables) != 'undefined' ){
30
+ jQuery.each(translatables, function(index,value){
31
+ /*
32
+ jQuery(value.tag).html(decodeURI(value.locales[l]));
33
+ decodeURI mucked up decoding Entities
34
+ */
35
+ jQuery(value.tag).html(decodeURIComponent(value.locales[l]));
36
+ jQuery(value.tag).fadeIn('slow'); /* pointless */
37
+ })
38
+ }
39
+ };
40
+ translate(locale);
41
+
42
+ });
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jakewendt-simply_pages
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
11
+ platform: ruby
12
+ authors:
13
+ - George 'Jake' Wendt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-30 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A really simple CMS
23
+ email: github@jakewendt.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - generators/simply_pages/USAGE
32
+ - generators/simply_pages/simply_pages_generator.rb
33
+ - generators/simply_pages/templates/autotest_simply_pages.rb
34
+ - generators/simply_pages/templates/controllers/locales_controller.rb
35
+ - generators/simply_pages/templates/controllers/pages_controller.rb
36
+ - generators/simply_pages/templates/functional/locales_controller_test.rb
37
+ - generators/simply_pages/templates/functional/pages_controller_test.rb
38
+ - generators/simply_pages/templates/images/drag.gif
39
+ - generators/simply_pages/templates/javascripts/pages.js
40
+ - generators/simply_pages/templates/migrations/create_pages.rb
41
+ - generators/simply_pages/templates/models/page.rb
42
+ - generators/simply_pages/templates/models/page_sweeper.rb
43
+ - generators/simply_pages/templates/simply_pages.rake
44
+ - generators/simply_pages/templates/stylesheets/page.css
45
+ - generators/simply_pages/templates/stylesheets/pages.css
46
+ - generators/simply_pages/templates/unit/page_test.rb
47
+ - generators/simply_pages/templates/unit/redcloth_extension_test.rb
48
+ - generators/simply_pages/templates/views/pages/_child.html.erb
49
+ - generators/simply_pages/templates/views/pages/_form.html.erb
50
+ - generators/simply_pages/templates/views/pages/_page.html.erb
51
+ - generators/simply_pages/templates/views/pages/all.html.erb
52
+ - generators/simply_pages/templates/views/pages/edit.html.erb
53
+ - generators/simply_pages/templates/views/pages/index.html.erb
54
+ - generators/simply_pages/templates/views/pages/new.html.erb
55
+ - generators/simply_pages/templates/views/pages/show.html.erb
56
+ - generators/simply_pages/templates/views/pages/translate.js.erb
57
+ - README.rdoc
58
+ has_rdoc: true
59
+ homepage: http://github.com/jakewendt/simply_pages
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.6.2
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A simple CMS
92
+ test_files: []
93
+