refinerycms-polls 0.0.1.dev

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 (68) hide show
  1. data/.gitignore +55 -0
  2. data/Gemfile +71 -0
  3. data/Guardfile +27 -0
  4. data/README.md +35 -0
  5. data/Rakefile +20 -0
  6. data/app/assets/images/refinery/polls/pollbg.gif +0 -0
  7. data/app/assets/javascripts/refinery/polls/poll_form.js +8 -0
  8. data/app/assets/stylesheets/refinery/polls/poll_form.css.scss +31 -0
  9. data/app/controllers/refinery/polls/admin/answers_controller.rb +55 -0
  10. data/app/controllers/refinery/polls/admin/questions_controller.rb +11 -0
  11. data/app/controllers/refinery/polls/questions_controller.rb +62 -0
  12. data/app/models/refinery/polls/answer.rb +39 -0
  13. data/app/models/refinery/polls/question.rb +60 -0
  14. data/app/models/refinery/polls/setting.rb +62 -0
  15. data/app/models/refinery/polls/vote.rb +34 -0
  16. data/app/views/refinery/polls/admin/answers/_actions.html.erb +25 -0
  17. data/app/views/refinery/polls/admin/answers/_answer.html.erb +16 -0
  18. data/app/views/refinery/polls/admin/answers/_answers.html.erb +2 -0
  19. data/app/views/refinery/polls/admin/answers/_form.html.erb +17 -0
  20. data/app/views/refinery/polls/admin/answers/_records.html.erb +18 -0
  21. data/app/views/refinery/polls/admin/answers/_sorteable_list.html.erb +5 -0
  22. data/app/views/refinery/polls/admin/answers/edit.html.erb +1 -0
  23. data/app/views/refinery/polls/admin/answers/index.html.erb +7 -0
  24. data/app/views/refinery/polls/admin/answers/new.html.erb +1 -0
  25. data/app/views/refinery/polls/admin/questions/_actions.html.erb +25 -0
  26. data/app/views/refinery/polls/admin/questions/_form.html.erb +29 -0
  27. data/app/views/refinery/polls/admin/questions/_question.html.erb +22 -0
  28. data/app/views/refinery/polls/admin/questions/_questions.html.erb +2 -0
  29. data/app/views/refinery/polls/admin/questions/_records.html.erb +18 -0
  30. data/app/views/refinery/polls/admin/questions/_sortable_list.html.erb +5 -0
  31. data/app/views/refinery/polls/admin/questions/edit.html.erb +1 -0
  32. data/app/views/refinery/polls/admin/questions/index.html.erb +7 -0
  33. data/app/views/refinery/polls/admin/questions/new.html.erb +1 -0
  34. data/app/views/refinery/polls/questions/_answers_form.html.erb +10 -0
  35. data/app/views/refinery/polls/questions/_poll.html.erb +10 -0
  36. data/app/views/refinery/polls/questions/_results.html.erb +14 -0
  37. data/app/views/refinery/polls/questions/index.html.erb +11 -0
  38. data/app/views/refinery/polls/questions/results.html.erb +0 -0
  39. data/app/views/refinery/polls/questions/show.html.erb +39 -0
  40. data/app/views/refinery/polls/questions/submit.js.erb +1 -0
  41. data/config/locales/en.yml +44 -0
  42. data/config/locales/es.yml +31 -0
  43. data/config/locales/fr.yml +30 -0
  44. data/config/locales/nb.yml +30 -0
  45. data/config/locales/nl.yml +30 -0
  46. data/config/routes.rb +33 -0
  47. data/db/migrate/1_create_polls_questions.rb +41 -0
  48. data/db/migrate/2_create_polls_answers.rb +25 -0
  49. data/db/migrate/3_create_polls_votes.rb +14 -0
  50. data/db/migrate/4_add_slug_to_questions_and_answers.rb +9 -0
  51. data/db/migrate/5_create_polls_translations.rb +22 -0
  52. data/db/seeds.rb +24 -0
  53. data/lib/generators/refinery/polls_generator.rb +25 -0
  54. data/lib/generators/refinery/templates/config/initializers/refinery/poll.rb.erb +4 -0
  55. data/lib/refinery/polls/configuration.rb +10 -0
  56. data/lib/refinery/polls/engine.rb +26 -0
  57. data/lib/refinery/polls/version.rb +18 -0
  58. data/lib/refinery/polls.rb +21 -0
  59. data/lib/refinerycms-polls.rb +1 -0
  60. data/lib/tasks/refinery/polls.rake +13 -0
  61. data/refinerycms-polls.gemspec +27 -0
  62. data/spec/models/refinery/polls/question_spec.rb +18 -0
  63. data/spec/requests/refinery/polls/admin/questions_spec.rb +101 -0
  64. data/spec/spec_helper.rb +50 -0
  65. data/spec/support/factories/refinery/polls.rb +7 -0
  66. data/tasks/rspec.rake +6 -0
  67. data/tasks/testing.rake +8 -0
  68. metadata +163 -0
@@ -0,0 +1,7 @@
1
+ <section id='records'>
2
+ <%= render 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render 'actions' %>
6
+ </aside>
7
+ <%= render '/refinery/admin/make_sortable', :tree => false if !searching? and ::Refinery::Polls::Admin::AnswersController.sortable? and ::Refinery::Polls::Answer.count > 1 %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,25 @@
1
+ <ul>
2
+ <% if ::Refinery::Polls::Admin::QuestionsController.searchable? %>
3
+ <li>
4
+ <%= render '/refinery/admin/search', :url => refinery.polls_admin_questions_path %>
5
+ </li>
6
+ <% end %>
7
+ <li>
8
+ <%= link_to t('.create_new'), refinery.new_polls_admin_question_path,
9
+ :class => "add_icon" %>
10
+ </li>
11
+ <% if !searching? && ::Refinery::Polls::Admin::QuestionsController.sortable? && ::Refinery::Polls::Question.any? %>
12
+ <li>
13
+ <%= link_to t('.reorder', :what => "Polls"),
14
+ refinery.polls_admin_questions_path,
15
+ :id => "reorder_action",
16
+ :class => "reorder_icon" %>
17
+
18
+ <%= link_to t('.reorder_done', :what => "Polls"),
19
+ refinery.polls_admin_questions_path,
20
+ :id => "reorder_action_done",
21
+ :style => "display: none;",
22
+ :class => "reorder_icon" %>
23
+ </li>
24
+ <% end %>
25
+ </ul>
@@ -0,0 +1,29 @@
1
+ <%= form_for [refinery, :polls_admin, @question] do |f| -%>
2
+ <%= render '/refinery/admin/error_messages',
3
+ :object => @question,
4
+ :include_object_name => true %>
5
+
6
+
7
+ <div class='field'>
8
+ <%= f.label :title -%>
9
+ <%= f.text_field :title, :class => 'larger widest' -%>
10
+
11
+ </div>
12
+
13
+ <div class='field'>
14
+ <%= f.label :start_date -%>
15
+ <%= f.datetime_select :start_date -%>
16
+
17
+ </div>
18
+
19
+ <div class='field'>
20
+ <%= f.label :end_date -%>
21
+ <%= f.datetime_select :end_date -%>
22
+
23
+ </div>
24
+
25
+ <%= render '/refinery/admin/form_actions', :f => f,
26
+ :continue_editing => false,
27
+ :delete_title => t('delete', :scope => 'refinery.polls.admin.questions.poll'),
28
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @question.title) %>
29
+ <% end -%>
@@ -0,0 +1,22 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(question) -%>">
2
+ <span class='title'>
3
+ <%= question.title %>
4
+
5
+ </span>
6
+ <span class='actions'>
7
+
8
+ <%= link_to refinery_icon_tag("application_go.png"), refinery.polls_question_path(question),
9
+ :title => t('.view_live_html'),
10
+ :target => "_blank" %>
11
+
12
+ <%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_polls_admin_question_path(question),
13
+ :title => t('.edit') %>
14
+ <%= link_to refinery_icon_tag("delete.png"), refinery.polls_admin_question_path(question),
15
+ :class => "cancel confirm-delete",
16
+ :title => t('.delete'),
17
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => question.title),
18
+ :method => :delete %>
19
+ <%= link_to refinery_icon_tag("page_add.png"), refinery.polls_admin_question_answers_path(question),
20
+ :title => t('.manage_answers') %>
21
+ </span>
22
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @questions if Refinery::Polls::Admin::QuestionsController.pageable? %>
2
+ <%= render 'sortable_list' %>
@@ -0,0 +1,18 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <div class='pagination_container'>
5
+ <% if @questions.any? %>
6
+ <%= render 'questions' %>
7
+ <% else %>
8
+ <p>
9
+ <% unless searching? %>
10
+ <strong>
11
+ <%= t('.no_items_yet') %>
12
+ </strong>
13
+ <% else %>
14
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
15
+ <% end %>
16
+ </p>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,5 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'question', :collection => @questions %>
3
+ </ul>
4
+ <%= render '/refinery/admin/sortable_list',
5
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,7 @@
1
+ <section id='records'>
2
+ <%= render 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render 'actions' %>
6
+ </aside>
7
+ <%= render '/refinery/admin/make_sortable', :tree => false if !searching? and ::Refinery::Polls::Admin::QuestionsController.sortable? and ::Refinery::Polls::Question.count > 1 %>
@@ -0,0 +1 @@
1
+ <%= render 'form' %>
@@ -0,0 +1,10 @@
1
+ <ul>
2
+ <%= form_for :question,
3
+ :url => refinery.submit_polls_question_path(question),
4
+ :remote => true,
5
+ :html => {:id => "reinerycms-poll-#{question.slug}"} do |f| %>
6
+ <% question.answers.each do |answer| %>
7
+ <li><%= radio_button_tag("answer_id", answer.id, false) %> <%= answer.title %></li>
8
+ <% end %>
9
+ <% end %>
10
+ </ul>
@@ -0,0 +1,10 @@
1
+ <% content_for :stylesheets, stylesheet_link_tag('refinery/polls/poll_form') %>
2
+ <% if question %>
3
+ <div id="reinerycms-poll-<%=question.slug%>" class="reinerycms-polls-form">
4
+ <h3><%= question.title %></h3>
5
+ <% if question %>
6
+ <%= (vote = ::Refinery::Polls::Vote.get_vote(question, request.remote_ip)).nil? ? render(:partial => 'refinery/polls/questions/answers_form', :locals => {:question => question}) : render(:partial => 'refinery/polls/questions/results', :locals => {:question => question, :vote => vote}) %>
7
+ <% end %>
8
+ </div>
9
+ <% content_for :javascripts, javascript_include_tag('application', 'refinery/polls/poll_form') %>
10
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <% if question && vote %>
2
+ <p>Your vote was: <%= vote.answer.title %></p>
3
+ <ul class="reinerycms-polls-results">
4
+ <% answers_with_data, total_votes = question.answers_with_data %>
5
+ <% answers_with_data.each do |answer_with_data| %>
6
+ <li>
7
+ <span><%= answer_with_data[0] %></span>
8
+ <small><i>(<%= number_to_percentage((answer_with_data[1].to_f/total_votes.to_f)*100, :precision => 2) %>, <%= "#{answer_with_data[1]} votes" %>)</i></small>
9
+ <div class="reinerycms-polls-pollbar" style="width: <%=number_to_percentage((answer_with_data[1].to_f/total_votes.to_f)*100, :precision => 0)%>;"></div>
10
+ </li>
11
+ <% end %>
12
+ <li><small>Total voters: <%=total_votes%></small></li>
13
+ </ul>
14
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% content_for :body_content_left do %>
2
+ <ul id="questions">
3
+ <% @questions.each do |poll| %>
4
+ <li>
5
+ <%= link_to question.title, refinery.polls_question_path(question) %>
6
+ </li>
7
+ <% end %>
8
+ </ul>
9
+ <% end %>
10
+
11
+ <%= render '/refinery/content_page' %>
@@ -0,0 +1,39 @@
1
+ <% content_for :body_content_title do %>
2
+ <%= @question.title %>
3
+ <% end %>
4
+
5
+ <% content_for :body_content_left do %>
6
+ <section>
7
+ <h1>Title</h1>
8
+ <p>
9
+ <%=raw @question.title %>
10
+ </p>
11
+ </section>
12
+ <section>
13
+ <h1>Start Date</h1>
14
+ <p>
15
+ <%=raw @question.start_date %>
16
+ </p>
17
+ </section>
18
+ <section>
19
+ <h1>End Date</h1>
20
+ <p>
21
+ <%=raw @question.end_date %>
22
+ </p>
23
+ </section>
24
+ <% end %>
25
+
26
+ <% content_for :body_content_right do %>
27
+ <aside>
28
+ <h2><%= t('.other') %></h2>
29
+ <ul id="questions">
30
+ <% @questions.each do |poll| %>
31
+ <li>
32
+ <%= link_to question.title, refinery.polls_question_path(question) %>
33
+ </li>
34
+ <% end %>
35
+ </ul>
36
+ </aside>
37
+ <% end %>
38
+
39
+ <%= render '/refinery/content_page' %>
@@ -0,0 +1 @@
1
+ $("#reinerycms-poll-<%=@question.slug%>").html('<%= escape_javascript render(:partial => "results", :locals => {:question => @question, :vote => @vote}) %>');
@@ -0,0 +1,44 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ polls:
5
+ title: Polls
6
+ polls:
7
+ admin:
8
+ questions:
9
+ actions:
10
+ create_new: Add New Poll
11
+ reorder: Reorder Polls
12
+ reorder_done: Done Reordering Polls
13
+ records:
14
+ title: Polls
15
+ sorry_no_results: Sorry! There are no results found.
16
+ no_items_yet: There are no Polls yet. Click "Add New Poll" to add your first poll.
17
+ question:
18
+ view_live_html: View this poll live <br/><em>(opens in a new window)</em>
19
+ edit: Edit this poll
20
+ delete: Remove this poll forever
21
+ manage_answers: View answers for this poll
22
+ answers:
23
+ actions:
24
+ create_new: Add New Poll Answer
25
+ reorder: Reorder Poll Answers
26
+ reorder_done: Done Reordering Poll Answers
27
+ records:
28
+ title: Poll Answers
29
+ sorry_no_results: Sorry! There are no results found.
30
+ no_items_yet: There are no Poll Answers yet. Click "Add New Poll Answer" to add your first poll answer.
31
+ answer:
32
+ view_live_html: View this poll answer live <br/><em>(opens in a new window)</em>
33
+ edit: Edit this poll answer
34
+ delete: Remove this poll answer forever
35
+ questions:
36
+ show:
37
+ other: Other Polls
38
+ activerecord:
39
+ attributes:
40
+ 'refinery/polls/question':
41
+ title: Title
42
+ start_date: Start Date
43
+ end_date: End Date
44
+ position: Position
@@ -0,0 +1,31 @@
1
+ es:
2
+ refinery:
3
+ plugins:
4
+ polls:
5
+ title: Polls
6
+ # article: masculino/femenino
7
+ polls:
8
+ admin:
9
+ questions:
10
+ actions:
11
+ create_new: Crear nuevo poll
12
+ reorder: Reordenar polls
13
+ reorder_done: Reordenación de polls completada
14
+ records:
15
+ title: Polls
16
+ sorry_no_results: Lo siento, no hay resultados
17
+ no_items_yet: No hay polls todavía. Pulsa en "Crear nuevo Poll" para crear tu primer poll.
18
+ question:
19
+ view_live_html: Ver este poll como abierto al público <br/><em>(abre en ventana nueva)</em>
20
+ edit: Editar este poll
21
+ delete: Borrar este poll para siempre
22
+ questions:
23
+ show:
24
+ other: Otros polls
25
+ activerecord:
26
+ attributes:
27
+ 'refinery/polls/question':
28
+ title: Title
29
+ start_date: Start Date
30
+ end_date: End Date
31
+ position: Position
@@ -0,0 +1,30 @@
1
+ fr:
2
+ refinery:
3
+ plugins:
4
+ polls:
5
+ title: Polls
6
+ polls:
7
+ admin:
8
+ questions:
9
+ actions:
10
+ create_new: Créer un(e) nouve(au/l/lle) Poll
11
+ reorder: Réordonner les Polls
12
+ reorder_done: Fin de réordonnancement des Polls
13
+ records:
14
+ title: Polls
15
+ sorry_no_results: "Désolé ! Aucun résultat."
16
+ no_items_yet: 'Il n''y a actuellement aucun(e) Poll. Cliquer sur "Créer un(e) nouve(au/l/lle) Poll" pour créer votre premi(er/ère) poll.'
17
+ question:
18
+ view_live_html: Voir ce(t/tte) poll <br/><em>(Ouvre une nouvelle fenêtre)</em>
19
+ edit: Modifier ce(t/tte) poll
20
+ delete: Supprimer définitivement ce(t/tte) poll
21
+ questions:
22
+ show:
23
+ other: Autres Polls
24
+ activerecord:
25
+ attributes:
26
+ 'refinery/polls/question':
27
+ title: Title
28
+ start_date: Start Date
29
+ end_date: End Date
30
+ position: Position
@@ -0,0 +1,30 @@
1
+ nb:
2
+ refinery:
3
+ plugins:
4
+ polls:
5
+ title: Polls
6
+ polls:
7
+ admin:
8
+ questions:
9
+ actions:
10
+ create_new: Lag en ny Poll
11
+ reorder: Endre rekkefølgen på Polls
12
+ reorder_done: Ferdig å endre rekkefølgen Polls
13
+ records:
14
+ title: Polls
15
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
16
+ no_items_yet: Det er ingen Polls enda. Klikk på "Lag en ny Poll" for å legge til din første poll.
17
+ question:
18
+ view_live_html: Vis hvordan denne poll ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
19
+ edit: Rediger denne poll
20
+ delete: Fjern denne poll permanent
21
+ questions:
22
+ show:
23
+ other: Andre Polls
24
+ activerecord:
25
+ attributes:
26
+ 'refinery/polls/question':
27
+ title: Title
28
+ start_date: Start Date
29
+ end_date: End Date
30
+ position: Position
@@ -0,0 +1,30 @@
1
+ nl:
2
+ refinery:
3
+ plugins:
4
+ polls:
5
+ title: Polls
6
+ polls:
7
+ admin:
8
+ questions:
9
+ actions:
10
+ create_new: Maak een nieuwe Poll
11
+ reorder: Wijzig de volgorde van de Polls
12
+ reorder_done: Klaar met het wijzingen van de volgorde van de Polls
13
+ records:
14
+ title: Polls
15
+ sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
16
+ no_items_yet: Er zijn nog geen Polls. Druk op 'Maak een nieuwe Poll' om de eerste aan te maken.
17
+ question:
18
+ view_live_html: Bekijk deze poll op de website <br/><em>(opent een nieuw venster)</em>
19
+ edit: Bewerk deze poll
20
+ delete: Verwijder deze poll voor eeuwig
21
+ questions:
22
+ show:
23
+ other: Andere Polls
24
+ activerecord:
25
+ attributes:
26
+ 'refinery/polls/question':
27
+ title: Title
28
+ start_date: Start Date
29
+ end_date: End Date
30
+ position: Position
data/config/routes.rb ADDED
@@ -0,0 +1,33 @@
1
+ Refinery::Core::Engine.routes.append do
2
+
3
+ # Frontend routes
4
+ namespace :polls do
5
+ resources :questions, :path => '', :only => [:index, :show] do
6
+ member do
7
+ post 'submit'
8
+ get 'widget'
9
+ end
10
+ end
11
+ end
12
+ # namespace :poll_answers do
13
+ # resources :polls, :path => '', :only => [:index, :show]
14
+ # end
15
+
16
+ # Admin routes
17
+ namespace :polls, :path => '' do
18
+ namespace :admin, :path => 'refinery' do
19
+ match "/refinery/questions/:question_id/answers" => "refinery/polls/admin/answers#index", :as => :answer
20
+ resources :questions, :except => :show do
21
+ collection do
22
+ post :update_positions
23
+ end
24
+ resources :answers, :except => :show do
25
+ collection do
26
+ post :update_positions
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,41 @@
1
+ class CreatePollsQuestions < ActiveRecord::Migration
2
+
3
+ def up
4
+
5
+ create_table Refinery::Polls::Question.table_name, :id => true do |t|
6
+ t.string :title
7
+ t.datetime :start_date
8
+ t.datetime :end_date
9
+ t.integer :position
10
+ t.timestamps
11
+ end
12
+ # User.find(:all).each do |user|
13
+ # user.plugins.create(:title => "Polls", :position => (user.plugins.maximum(:position) || -1) +1)
14
+ # end
15
+ # page = Page.create(
16
+ # :title => "Polls",
17
+ # :link_url => "/polls",
18
+ # :deletable => false,
19
+ # :position => ((Page.maximum(:position, :conditions => "parent_id IS NULL") || -1)+1),
20
+ # :menu_match => "^/polls(\/|\/.+?|)$"
21
+ # )
22
+ # RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"]).each do |default_page_part|
23
+ # page.parts.create(:title => default_page_part, :body => nil)
24
+ # end
25
+
26
+ end
27
+
28
+ def down
29
+ if defined?(::Refinery::UserPlugin)
30
+ ::Refinery::UserPlugin.destroy_all({:name => "refinerycms-polls"})
31
+ end
32
+
33
+ if defined?(::Refinery::Page)
34
+ ::Refinery::Page.delete_all({:link_url => "/polls/polls"})
35
+ end
36
+
37
+ drop_table Refinery::Polls::Question.table_name
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ class CreatePollsAnswers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table Refinery::Polls::Answer.table_name, :id => true do |t|
4
+ t.string :title
5
+ t.integer :votes_count, :default => 0
6
+ t.integer :position
7
+ t.integer :question_id
8
+ t.timestamps
9
+ end
10
+
11
+ end
12
+
13
+ def self.down
14
+ if defined?(::Refinery::UserPlugin)
15
+ ::Refinery::UserPlugin.destroy_all({:name => "refinerycms-polls"})
16
+ end
17
+
18
+ # no necesitamos una vista de las respuestas solas por ahora.
19
+ # if defined?(::Refinery::Page)
20
+ # ::Refinery::Page.delete_all({:link_url => "/polls/polls_answers"})
21
+ # end
22
+
23
+ drop_table Refinery::Polls::Answer.table_name
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePollsVotes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table Refinery::Polls::Vote.table_name, :id => true do |t|
4
+ t.integer :question_id
5
+ t.integer :answer_id
6
+ t.string :ip
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table Refinery::Polls::Vote.table_name
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class AddSlugToQuestionsAndAnswers < ActiveRecord::Migration
2
+ def change
3
+ add_column Refinery::Polls::Question.table_name, :slug, :string
4
+ add_index Refinery::Polls::Question.table_name, :slug
5
+
6
+ add_column Refinery::Polls::Answer.table_name, :slug, :string
7
+ add_index Refinery::Polls::Answer.table_name, :slug
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ class CreatePollsTranslations < ActiveRecord::Migration
2
+ def up
3
+ Refinery::Polls::Question.create_translation_table!({
4
+ :title => :string,
5
+ :slug => :string
6
+ }, {
7
+ :migrate_data => true
8
+ })
9
+ Refinery::Polls::Answer.create_translation_table!({
10
+ :title => :string,
11
+ :slug => :string
12
+ }, {
13
+ :migrate_data => true
14
+ })
15
+
16
+ end
17
+
18
+ def down
19
+ Refinery::Polls::Question.drop_translation_table! :migrate_data => true
20
+ Refinery::Polls::Answer.drop_translation_table! :migrate_data => true
21
+ end
22
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,24 @@
1
+ if defined?(::Refinery::User)
2
+ ::Refinery::User.all.each do |user|
3
+ if user.plugins.where(:name => 'refinerycms-polls').blank?
4
+ user.plugins.create(:name => 'refinerycms-polls',
5
+ :position => (user.plugins.maximum(:position) || -1) +1)
6
+ end
7
+ end
8
+ end
9
+
10
+
11
+ url = "/polls"
12
+ if defined?(::Refinery::Page) && ::Refinery::Page.where(:link_url => url).empty?
13
+ page = ::Refinery::Page.create(
14
+ :title => 'Polls',
15
+ :link_url => url,
16
+ :deletable => false,
17
+ :show_in_menu => false,
18
+ :menu_match => "^#{url}(\/|\/.+?|)$"
19
+ )
20
+ Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
21
+ page.parts.create(:title => default_page_part, :body => nil, :position => index)
22
+ end
23
+ end
24
+
@@ -0,0 +1,25 @@
1
+ module Refinery
2
+ class PollsGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def rake_db
6
+ rake("refinery_polls:install:migrations")
7
+ rake("refinery_polls:install:migrations")
8
+ end
9
+
10
+ def generate_poll_initializer
11
+ template "config/initializers/refinery/poll.rb.erb", File.join(destination_root, "config", "initializers", "refinery", "poll.rb")
12
+ end
13
+
14
+ def append_load_seed_data
15
+ create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
16
+ append_file 'db/seeds.rb', :verbose => true do
17
+ <<-EOH
18
+
19
+ # Added by Refinery CMS Poll engine
20
+ Refinery::Polls::Engine.load_seed
21
+ EOH
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ Refinery::Polls.configure do |config|
2
+ # Configure how long is going to be valid a vote for a guest
3
+ config.vote_duration = 1.week
4
+ end
@@ -0,0 +1,10 @@
1
+ module Refinery
2
+ module Polls
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :vote_duration
6
+
7
+ self.vote_duration = 1.week
8
+
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module Refinery
2
+ module Polls
3
+ class Engine < Rails::Engine
4
+ include Refinery::Engine
5
+ isolate_namespace Refinery::Polls
6
+
7
+ engine_name :refinery_polls
8
+
9
+ initializer "register refinerycms_polls plugin" do
10
+ Refinery::Plugin.register do |plugin|
11
+ plugin.name = "polls"
12
+ plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.polls_admin_questions_path }
13
+ plugin.pathname = root
14
+ plugin.activity = {
15
+ :class_name => :'refinery/polls/poll'
16
+ }
17
+
18
+ end
19
+ end
20
+
21
+ config.after_initialize do
22
+ Refinery.register_extension(Refinery::Polls)
23
+ end
24
+ end
25
+ end
26
+ end