spree_wordsmith 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/README.markdown +121 -0
  2. data/app/controllers/admin/pages_controller.rb +22 -0
  3. data/app/controllers/admin/posts_controller.rb +20 -0
  4. data/app/controllers/admin/wordsmith_settings_controller.rb +13 -0
  5. data/app/controllers/pages_controller.rb +19 -0
  6. data/app/controllers/posts_controller.rb +30 -0
  7. data/app/helpers/wordsmith_helper.rb +21 -0
  8. data/app/models/ability_decorator.rb +23 -0
  9. data/app/models/page.rb +4 -0
  10. data/app/models/post.rb +11 -0
  11. data/app/models/ws_item.rb +80 -0
  12. data/app/stylesheets/wordsmith.less +76 -0
  13. data/app/views/admin/pages/_form.html.erb +60 -0
  14. data/app/views/admin/pages/edit.html.erb +3 -0
  15. data/app/views/admin/pages/index.html.erb +25 -0
  16. data/app/views/admin/pages/new.html.erb +4 -0
  17. data/app/views/admin/posts/_form.html.erb +59 -0
  18. data/app/views/admin/posts/edit.html.erb +5 -0
  19. data/app/views/admin/posts/index.html.erb +25 -0
  20. data/app/views/admin/posts/new.html.erb +6 -0
  21. data/app/views/admin/posts/show.html.erb +27 -0
  22. data/app/views/admin/shared/_wordsmith_sub_menu.html.erb +8 -0
  23. data/app/views/admin/users/_display_name.html.erb +4 -0
  24. data/app/views/admin/wordsmith_settings/edit.html.erb +34 -0
  25. data/app/views/admin/wordsmith_settings/show.html.erb +37 -0
  26. data/app/views/content/show.html.erb +5 -0
  27. data/app/views/pages/index.html.erb +6 -0
  28. data/app/views/pages/show.html.erb +4 -0
  29. data/app/views/posts/_post.html.erb +11 -0
  30. data/app/views/posts/index.html.erb +13 -0
  31. data/app/views/posts/index.rss.builder +19 -0
  32. data/app/views/posts/show.html.erb +10 -0
  33. data/app/views/posts/tags.html.erb +18 -0
  34. data/app/views/shared/_recent_articles.html.erb +7 -0
  35. data/app/views/shared/_wordsmith_content_for.html.erb +7 -0
  36. data/lib/extensions/string.rb +20 -0
  37. data/lib/spree_wordsmith.rb +72 -0
  38. data/lib/spree_wordsmith_hooks.rb +8 -0
  39. data/lib/tasks/install.rake +33 -0
  40. data/lib/tasks/spree_wordsmith.rake +21 -0
  41. data/spec/controllers/admin/pages_controller_spec.rb +10 -0
  42. data/spec/controllers/admin/posts_controller_spec.rb +10 -0
  43. data/spec/controllers/posts_controller_spec.rb +27 -0
  44. data/spec/factories.rb +34 -0
  45. data/spec/models/posts_spec.rb +9 -0
  46. data/spec/spec_helper.rb +39 -0
  47. metadata +326 -0
@@ -0,0 +1,60 @@
1
+
2
+ <% form_for([:admin, @page]) do |f| %>
3
+ <%= f.error_messages %>
4
+ <div style="float:left; margin-right: 20px; padding-right: 20px; width:700px; border-right: solid 1px #999;">
5
+ <p>
6
+ <%= f.label :title, t("title") %><br />
7
+ <%= f.text_field :title, {:style => "width:100%;font-size:1.7em"} %>
8
+ </p>
9
+
10
+ <p>
11
+ <%= f.label :permalink, t("permalink") %><br />
12
+ <%= f.text_field :permalink %>
13
+ </p>
14
+
15
+ <p>
16
+ <%= f.label :body, t("body") %><br />
17
+ <%= f.text_area :body_raw, {:style => "width:100%;"} %>
18
+ </p>
19
+
20
+ <p>
21
+ <%= f.label :order_number, t("order_number") %><br />
22
+ <%= f.text_field :order_number %>
23
+ </p>
24
+
25
+ <p>
26
+ <%= f.label :list_page, t("list_page") %><br />
27
+ <%= f.check_box :list_page %>
28
+ </p>
29
+
30
+ <div id="extended-metadata">
31
+ <p>
32
+ <%= f.label :meta_keywords, t("meta_keywords") %> (comma separated)<br />
33
+ <%= f.text_field :meta_keywords, {:style => "width:100%"} %>
34
+ </p>
35
+
36
+ <p>
37
+ <%= f.label :meta_description, t("meta_description") %><br />
38
+ <%= f.text_field :meta_description, {:style => "width:100%"} %>
39
+ </p>
40
+ </div>
41
+
42
+
43
+ </div>
44
+
45
+ <div style="float:left; margin-right: 0;">
46
+ <p>
47
+ <%= f.label :user_id, t("author") %>
48
+ <%= f.select :user_id, User.all.collect {|r| [ r.display_name, r.id]} %>
49
+ </p>
50
+
51
+ <p>
52
+ <%= f.label :is_active, t("status") %>: <%= f.radio_button :is_active, 1 %><%= t("publish") %> <%= f.radio_button :is_active, 0 %><%= t("draft") %>
53
+ </p>
54
+
55
+ <p>
56
+ <%= f.submit button_name, :disable_with => 'Please wait...' %> | <%= link_to t("cancel"), admin_pages_path %><%- unless f.object.new_record? -%> | <%= link_to t("destroy"), [:admin, @page], :confirm => 'Are you sure?', :method => :delete %> <%- end -%>
57
+ </p>
58
+ </div>
59
+ <% end %>
60
+ <br class="clear"/>
@@ -0,0 +1,3 @@
1
+ <h1><%= t('edit-page') %></h1>
2
+
3
+ <%= render :partial => 'form', :locals => { :button_name => t("update")} %>
@@ -0,0 +1,25 @@
1
+ <%= render :partial => 'admin/shared/wordsmith_sub_menu' %>
2
+
3
+ <h1><%= t("pages") %></h1>
4
+
5
+ <table>
6
+ <tr>
7
+ <th><%= t('page') %></th>
8
+ <th><%= t('author') %></th>
9
+ <th><%= t('order_number') %></th>
10
+ <th><%= t('list_page') %></th>
11
+ <th><%= t('date') %></th>
12
+ </tr>
13
+ <% for page in @pages %>
14
+ <tr>
15
+ <td><%= link_to h(page.title), [:edit,:admin,page] %> (<%= page.is_active == 1 ? t("published") : t("draft") %>) </td>
16
+ <td><%= link_to page.user.display_name, [:admin, page.user] %></td>
17
+ <td><%= page.order_number %></td>
18
+ <td><%= page.list_page ? t('yes') : t('no') %></td>
19
+ <td><%= (page.published_at.blank? ? page.updated_at : page.published_at).strftime("%B %d, %Y at %I:%M%p") %></td>
20
+ <td><%= t("view") %> | <%= link_to t("edit"), [:edit, :admin, page] %> | <%= link_to t("delete"), [:admin, page], :confirm => 'Are you sure?', :method => :delete %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <p><%= link_to t("new-page"), new_admin_page_path %></p>
@@ -0,0 +1,4 @@
1
+ <h1><%= t('new-page') %></h1>
2
+
3
+ <%= render :partial => 'form', :locals => { :button_name => t("create")} %>
4
+
@@ -0,0 +1,59 @@
1
+
2
+ <% form_for([:admin, @post]) do |f| %>
3
+ <%= f.error_messages %>
4
+ <div style="float:left; margin-right: 20px; padding-right: 20px; width:700px; border-right: solid 1px #999;">
5
+ <p>
6
+ <%= f.label :title, t("title") %><br />
7
+ <%= f.text_field :title, {:style => "width:100%;font-size:1.7em"} %>
8
+ </p>
9
+ <% unless f.object.new_record? %>
10
+ <p>
11
+ <%= f.label :permalink, t("permalink") %><br />
12
+ <%= f.text_field :permalink %>
13
+ </p>
14
+ <% end %>
15
+ <p>
16
+ <%= f.label :body, t("body") %><br />
17
+ <%= f.text_area :body_raw, {:style => "width:100%;"} %>
18
+ </p>
19
+ <p>
20
+ <%= f.label :excerpt, t("excerpt") %><br />
21
+ <%= f.text_area :excerpt, { :rows=>"3", :style => "height:100%; width:100%;" } %>
22
+ </p>
23
+
24
+ <div id="extended-metadata">
25
+ <p>
26
+ <%= f.label :meta_keywords, t("meta_keywords") %> (comma separated)<br />
27
+ <%= f.text_field :meta_keywords, {:style => "width:100%"} %>
28
+ </p>
29
+
30
+ <p>
31
+ <%= f.label :meta_description, t("meta_description") %><br />
32
+ <%= f.text_field :meta_description, {:style => "width:100%"} %>
33
+ </p>
34
+ </div>
35
+
36
+
37
+ </div>
38
+
39
+ <div style="float:left; margin-right: 0;">
40
+ <p>
41
+ <%= f.label :user_id, t("author") %>
42
+ <%= f.select :user_id, User.all.collect {|r| [ r.display_name, r.id]} %>
43
+ </p>
44
+
45
+ <p>
46
+ <%= f.label :is_active, t("status") %>: <%= f.radio_button :is_active, 1 %><%= t("publish") %> <%= f.radio_button :is_active, 0 %><%= t("draft") %>
47
+ </p>
48
+ <p>
49
+ <%= f.label :commentable, t("comment_status") %>: <%= f.radio_button :commentable, 1 %><%= t("open") %> <%= f.radio_button :commentable, 0 %><%= t("closed") %>
50
+ </p>
51
+ <p>
52
+ <%= f.label :tag_list, "#{t("tags")} (#{t("tags_hint")}):" %> <br/> <%= f.text_field :tag_list %>
53
+ </p>
54
+ <p>
55
+ <%= f.submit button_name, :disable_with => 'Please wait...' %> | <%= link_to t("cancel"), admin_posts_path %><%- unless f.object.new_record? -%> | <%= link_to t("destroy"), [:admin, @post], :confirm => 'Are you sure?', :method => :delete %> <%- end -%>
56
+ </p>
57
+ </div>
58
+ <% end %>
59
+ <br class="clear"/>
@@ -0,0 +1,5 @@
1
+ <%= render :partial => 'admin/shared/wordsmith_sub_menu' %>
2
+
3
+ <h1><%= t('edit-post') %></h1>
4
+
5
+ <%= render :partial => 'form', :locals => { :button_name => t("update")} %>
@@ -0,0 +1,25 @@
1
+ <%= render :partial => 'admin/shared/wordsmith_sub_menu' %>
2
+
3
+ <h1><%= t("posts") %></h1>
4
+
5
+ <table>
6
+ <tr>
7
+ <th>Post</th>
8
+ <th>Author</th>
9
+ <th>Tags</th>
10
+ <th>Comments</th>
11
+ <th>Date</th>
12
+ </tr>
13
+ <% for post in @posts %>
14
+ <tr>
15
+ <td><%= link_to h(post.title), [:edit,:admin,post] %> (<%= post.is_active == 1 ? t("published") : t("draft") %>) </td>
16
+ <td><%= link_to post.user.display_name, [:admin, post.user] %></td>
17
+ <td><%= post.tag_list %></td>
18
+ <td><%= (post.published_at.blank? ? post.updated_at : post.published_at).strftime("%B %d, %Y at %I:%M%p") %></td>
19
+ <td><%= t("view") %> | <%= link_to t("edit"), [:edit, :admin, post] %> | <%= link_to t("delete"), [:admin, post], :confirm => 'Are you sure?', :method => :delete %></td>
20
+
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <p><%= link_to t("new-post"), new_admin_post_path %></p>
@@ -0,0 +1,6 @@
1
+ <%= render :partial => 'admin/shared/wordsmith_sub_menu' %>
2
+
3
+ <h1><%= t('new-post') %></h1>
4
+
5
+ <%= render :partial => 'form', :locals => { :button_name => t("create")} %>
6
+
@@ -0,0 +1,27 @@
1
+
2
+ <p>
3
+ <strong>Title:</strong>
4
+ <%=h @post.title %>
5
+ </p>
6
+ <p>
7
+ <strong>Body:</strong>
8
+ <%= @post.body %>
9
+ </p>
10
+ <p>
11
+ <strong>Published At:</strong>
12
+ <%=h @post.published_at %>
13
+ </p>
14
+ <p>
15
+ <strong>Is Active:</strong>
16
+ <%=h @post.is_active %>
17
+ </p>
18
+ <p>
19
+ <strong>Permalink:</strong>
20
+ <%=h @post.permalink %>
21
+ </p>
22
+
23
+ <p>
24
+ <%= link_to "Edit", [:edit,:admin,@post] %> |
25
+ <%= link_to "Destroy", [:admin, @post], :confirm => 'Are you sure?', :method => :delete %> |
26
+ <%= link_to "View All", admin_posts_path %>
27
+ </p>
@@ -0,0 +1,8 @@
1
+ <% content_for :sub_menu do %>
2
+ <ul id="sub_nav">
3
+ <%= tab :wordsmith_settings %>
4
+ <%= tab :posts %>
5
+ <%= tab :pages %>
6
+ <%= tab :view_blog, :route => :posts, :css_class => 'last' %>
7
+ </ul>
8
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <p>
2
+ <%= f.label :display_name %> <br/>
3
+ <%= f.text_field :display_name %>
4
+ </p>
@@ -0,0 +1,34 @@
1
+ <%= render :partial => 'admin/shared/wordsmith_sub_menu' %>
2
+
3
+ <h1><%= t('wordsmith_settings') %></h1>
4
+
5
+ <% form_tag(admin_wordsmith_settings_path, :method => :put) do -%>
6
+
7
+
8
+
9
+ <p>
10
+ <label><%= t("wordsmith_posts_per_page") %></label>
11
+ <%= text_field_tag('preferences[wordsmith_posts_per_page]', Spree::Config[:wordsmith_posts_per_page]) %>
12
+ </p>
13
+ <p>
14
+ <label><%= t('wordsmith_posts_recent') %></label>
15
+ <%= text_field_tag('preferences[wordsmith_posts_recent]', Spree::Config[:wordsmith_posts_recent])%>
16
+ </p>
17
+
18
+ <p>
19
+ <label><%= t('wordsmith_post_status_default') %></label>
20
+ <%= radio_button_tag('preferences[wordsmith_post_status_default]', 1, Spree::Config[:wordsmith_post_status_default]) %> <%= t("publish") %>
21
+ <%= radio_button_tag('preferences[wordsmith_post_status_default]', 0, Spree::Config[:wordsmith_post_status_default] ) %> <%= t("draft") %>
22
+ </p>
23
+
24
+ <p>
25
+ <label><%= t('wordsmith_post_comment_default') %></label>
26
+ <%= radio_button_tag('preferences[wordsmith_post_comment_default]', 1, Spree::Config[:wordsmith_post_comment_default]) %> <%= t("open") %>
27
+ <%= radio_button_tag('preferences[wordsmith_post_comment_default]', 0, Spree::Config[:wordsmith_post_comment_default] ) %> <%= t("closed") %>
28
+ </p>
29
+
30
+ <p class="form-buttons">
31
+ <%= button t('update') %>
32
+ <%= t("or") %> <%= link_to t("cancel"), admin_wordsmith_settings_url %>
33
+ </p>
34
+ <% end -%>
@@ -0,0 +1,37 @@
1
+ <%= render :partial => 'admin/shared/wordsmith_sub_menu' %>
2
+
3
+ <h1><%= t("wordsmith_settings") %></h1>
4
+
5
+ <table>
6
+ <tr>
7
+ <th scope="row"><%= t("wordsmith_permalink") %>:</th>
8
+ <td><%= Spree::Config[:wordsmith_permalink] %></td>
9
+ </tr>
10
+ <tr>
11
+ <th scope="row"><%= t("wordsmith_posts_per_page") %>:</th>
12
+ <td><%= Spree::Config[:wordsmith_posts_per_page] %></td>
13
+ </tr>
14
+ <tr>
15
+ <th scope="row"><%= t("wordsmith_posts_recent") %>:</th>
16
+ <td><%= Spree::Config[:wordsmith_posts_recent] %></td>
17
+ </tr>
18
+
19
+ <tr>
20
+ <th scope="row"><%= t("wordsmith_post_status_default") %>:</th>
21
+ <td><%= (Spree::Config[:wordsmith_post_status_default] ? t("publish") : t("draft")) %></td>
22
+ </tr>
23
+
24
+ <tr>
25
+ <th scope="row"><%= t("wordsmith_post_comment_default") %>:</th>
26
+ <td><%= (Spree::Config[:wordsmith_post_comment_default] ? t("open") : t("closed")) %>
27
+ </td>
28
+ </tr>
29
+
30
+
31
+
32
+
33
+ </table>
34
+
35
+ <p><%= link_to_with_icon 'edit', t("edit"), edit_admin_wordsmith_settings_path %></p>
36
+
37
+
@@ -0,0 +1,5 @@
1
+ <h2><%=@page.title%></h2>
2
+
3
+ <div class="content">
4
+ <%=@page.body%>
5
+ </div>
@@ -0,0 +1,6 @@
1
+ <% @pages.each do |page| %>
2
+ <div class="page">
3
+ <h3><%= page.title %></h3>
4
+ <p><%= page.body.html_safe %></p>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <div class="page">
2
+ <h3><%= @page.title %></h3>
3
+ <p><%= @page.body.html_safe %></p>
4
+ </div>
@@ -0,0 +1,11 @@
1
+ <div id="post-<%= post.id %>" class="post">
2
+ <div class="post-date"><%= post.published_at.strftime("%A, %B %d, %Y") %></div>
3
+ <h2 class="post-title"><%= link_to_unless_current (post.title == '' ? '[Untitled]' : h(post.title)), post, {:title => post.title, :alt => "Link to #{post.title}"} %></h2>
4
+ <div class="post-meta">
5
+ <% unless post.user.display_name.blank? %>By <%= post.user.display_name %> <% end %> - <%= link_to "comments", post_path(post, :anchor => "disqus_thread") %>
6
+ </div>
7
+ <div class="post-content"><%= post.body.html_safe %></div>
8
+ <div class="post-meta"><% unless post.tags.empty? %><%= t("tags") %>: <%= linked_tag_list(post.tags) %><% end %></div>
9
+ </div>
10
+
11
+ <%= disqus_comment_counts %>
@@ -0,0 +1,13 @@
1
+ <% content_for :head do %>
2
+ <link rel="alternate" type="application/rss+xml" title="<%= t("posts") %> RSS" href="<%= posts_url(:format => 'rss') %>" />
3
+ <% end %>
4
+
5
+ <%= render 'shared/wordsmith_content_for'%>
6
+
7
+ <div class="posts">
8
+ <% for post in @posts %>
9
+ <%= render post %>
10
+ <% end %>
11
+
12
+ <%= will_paginate(:prev => "&#171; #{t('previous')}", :next => "#{t('next')} &#187;") %>
13
+ </div>
@@ -0,0 +1,19 @@
1
+ xml.instruct! :xml, :version => "1.0"
2
+ xml.rss :version => "2.0" do
3
+ xml.channel do
4
+ xml.title "#{Spree::Config[:site_name]}"
5
+ xml.description "#{Spree::Config[:wordsmith_rss_description]}"
6
+ xml.link posts_url(:format => 'rss')
7
+
8
+ @posts.each do |post|
9
+ xml.item do
10
+ xml.title post.title
11
+ xml.description post.body
12
+ xml.author post.user.display_name
13
+ xml.pubDate post.published_at.to_s(:rfc822)
14
+ xml.link post_url(:id => post)
15
+ xml.guid({:isPermaLink => "false"}, post_url(post))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+
2
+ <%= render 'shared/wordsmith_content_for'%>
3
+
4
+ <%= render @post %>
5
+
6
+ <% if @post.commentable == 1 %>
7
+ <div id="comments">
8
+ <%= disqus_thread %>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <%= render 'shared/wordsmith_content_for'%>
2
+
3
+ <h1><%= "'#{params[:tag_name]}' #{t("posts")}" %></h1>
4
+
5
+ <div class="posts">
6
+ <% unless @posts.empty? %>
7
+ <%= render @posts %>
8
+ <% else %>
9
+ <p><%= t("no_posts_found") %>.</p>
10
+ <% end %>
11
+ </div>
12
+
13
+
14
+ <p class="pagination">
15
+ <%= link_to h('< Previous Page'), :overwrite_params => { :page => @posts.previous_page } if @posts.previous_page %>
16
+ <%= "|" if @posts.previous_page && @posts.next_page %>
17
+ <%= link_to h('Next Page >'), :overwrite_params => { :page => @posts.next_page } if @posts.next_page %>
18
+ </p>
@@ -0,0 +1,7 @@
1
+ <h3><%= t("recent_posts") %></h3>
2
+ <ul>
3
+ <% post_link_list().each do |link| -%>
4
+ <li><%= link_to link.name, link.url %></li>
5
+ <% end -%>
6
+ <li><%- link_to posts_path(:format => 'rss') do -%><%= image_tag('icons/feed.gif', :alt => "#{t("posts")} RSS", :size => '16x16') %> RSS Feed <%- end -%></li>
7
+ </ul>
@@ -0,0 +1,7 @@
1
+ <% content_for :head do %>
2
+ <%= stylesheet_tags 'wordsmith' %>
3
+ <% end %>
4
+
5
+ <% content_for :sidebar do %>
6
+ <%= render 'shared/recent_articles'%>
7
+ <% end %>
@@ -0,0 +1,20 @@
1
+ module Extensions::String
2
+ def linkify
3
+ result = self.downcase
4
+ result.gsub!(/&(\d)+;/, '') # Ditch Entities
5
+ result.gsub!('&', 'and') # Replace & with 'and'
6
+ result.gsub!(/['"]/, '') # replace quotes by nothing
7
+ result.gsub!(/\W/, ' ') # strip all non word chars
8
+ result.gsub!(/\ +/, '-') # replace all white space sections with a dash
9
+ result.gsub!(/(-)$/, '') # trim dashes
10
+ result.gsub!(/^(-)/, '') # trim dashes
11
+ result.gsub!(/[^a-zA-Z0-9\-]/, '-') # Get rid of anything we don't like
12
+ result
13
+ end
14
+
15
+ def linkify!
16
+ self.replace(self.linkify)
17
+ end
18
+ end
19
+
20
+ String.send(:include, Extensions::String)