decidim-pages 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab78619392592e129e5832c0a779ef5283722b6a
4
+ data.tar.gz: 32f49164085f41b9f788ff173ddb1b1f1339726f
5
+ SHA512:
6
+ metadata.gz: cabddfa8a9fc6812b2bc7f41580bb2e01d5fc48307fb56f959295667bf4dd5cd04ac412606284151dc2db15c31a95088ea89e80719d42b1c6ff9a52fbc254778
7
+ data.tar.gz: 7553a56a6e9268c7f2bf87fd009b3a46b3edd99d905762deda8abb6443200ce4e978fa78fb0fc9777c43af179f92d59d17d40bb0489432c465c49b5d62026623
@@ -0,0 +1,24 @@
1
+ # Decidim::Pages
2
+
3
+ The Pages module adds static page capabilities to any participatory process. It basically provides an interface to include arbitrary HTML content to any step.
4
+
5
+ ## Usage
6
+ Pages will be available as a Feature for a Participatory Process.
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'decidim-pages'
13
+ ```
14
+
15
+ And then execute:
16
+ ```bash
17
+ $ bundle
18
+ ```
19
+
20
+ ## Contributing
21
+ See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
22
+
23
+ ## License
24
+ See [Decidim](https://github.com/AjuntamentdeBarcelona/decidim).
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require "decidim/common_rake"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ module Admin
5
+ # This command is executed when the user changes a Page from the admin
6
+ # panel.
7
+ class UpdatePage < Rectify::Command
8
+ # Initializes a UpdatePage Command.
9
+ #
10
+ # form - The form from which to get the data.
11
+ # page - The current instance of the page to be updated.
12
+ def initialize(form, page)
13
+ @form = form
14
+ @page = page
15
+ end
16
+
17
+ # Updates the page if valid.
18
+ #
19
+ # Broadcasts :ok if successful, :invalid otherwise.
20
+ def call
21
+ return broadcast(:invalid) if @form.invalid?
22
+
23
+ update_page
24
+ broadcast(:ok)
25
+ end
26
+
27
+ private
28
+
29
+ def update_page
30
+ @page.update_attributes!(
31
+ title: @form.title,
32
+ body: @form.body,
33
+ commentable: @form.commentable
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # Command that gets called whenever a feature's page has to be created. It
5
+ # usually happens as a callback when the feature itself is created.
6
+ class CreatePage < Rectify::Command
7
+ def initialize(feature)
8
+ @feature = feature
9
+ end
10
+
11
+ def call
12
+ @page = Page.new(
13
+ title: @feature.name,
14
+ feature: @feature
15
+ )
16
+
17
+ @page.save ? broadcast(:ok) : broadcast(:invalid)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # Command that gets called when the page of this feature needs to be
5
+ # destroyed. It usually happens as a callback when the feature is removed.
6
+ class DestroyPage < Rectify::Command
7
+ def initialize(feature)
8
+ @feature = feature
9
+ end
10
+
11
+ def call
12
+ Page.where(feature: @feature).destroy_all
13
+ broadcast(:ok)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Pages
5
+ module Admin
6
+ # Base controller for the administration of this module. It inherits from
7
+ # Decidim's admin base controller in order to inherit the layout and other
8
+ # convenience methods relevant to a this component.
9
+ class ApplicationController < Decidim::Admin::Features::BaseController
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ module Admin
5
+ # This controller allows the user to update a Page.
6
+ class PagesController < Admin::ApplicationController
7
+ def edit
8
+ @form = form(Admin::PageForm).from_model(page)
9
+ end
10
+
11
+ def update
12
+ @form = form(Admin::PageForm).from_params(params)
13
+
14
+ Admin::UpdatePage.call(@form, page) do
15
+ on(:ok) do
16
+ flash[:notice] = I18n.t("pages.update.success", scope: "decidim.pages.admin")
17
+ redirect_to parent_path
18
+ end
19
+
20
+ on(:invalid) do
21
+ flash.now[:alert] = I18n.t("pages.update.invalid", scope: "decidim.pages.admin")
22
+ render action: "edit"
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def page
30
+ @page ||= Pages::Page.find_by(feature: current_feature)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Pages
5
+ # This controller is the abstract class from which all other controllers of
6
+ # this engine inherit.
7
+ #
8
+ # Note that it inherits from `Decidim::Features::Basecontroller`, which
9
+ # override its layout and provide all kinds of useful methods.
10
+ class ApplicationController < Decidim::Features::BaseController
11
+ def show
12
+ @page = Page.find_by(feature: current_feature)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ module Admin
5
+ # This class holds a Form to update pages from Decidim's admin panel.
6
+ class PageForm < Decidim::Form
7
+ include TranslatableAttributes
8
+
9
+ translatable_attribute :title, String
10
+ translatable_attribute :body, String
11
+ attribute :commentable, Boolean
12
+
13
+ validates :title, translatable_presence: true
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # Custom helpers, scoped to the pages engine.
5
+ #
6
+ module ApplicationHelper
7
+ include Decidim::Comments::CommentsHelper
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # Abstract class from which all models in this engine inherit.
5
+ class ApplicationRecord < ActiveRecord::Base
6
+ self.abstract_class = true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # The data store for a Page in the Decidim::Pages component. It stores a
5
+ # title, description and any other useful information to render a custom page.
6
+ class Page < Pages::ApplicationRecord
7
+ validates :title, :feature, presence: true
8
+ belongs_to :feature, foreign_key: "decidim_feature_id", class_name: Decidim::Feature
9
+ has_one :organization, through: :feature
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ <div class="field">
2
+ <%= form.translated :text_field, :title, autofocus: true, label: t("models.components.title", scope: "decidim.pages.admin") %>
3
+ <%= form.translated :editor, :body, toolbar: :full, lines: 30, label: t("models.components.body", scope: "decidim.pages.admin") %>
4
+ <%= form.check_box :commentable, label: t("models.components.commentable", scope: "decidim.pages.admin") %>
5
+ </div>
@@ -0,0 +1,9 @@
1
+ <h3><%= t ".title" %></h3>
2
+
3
+ <%= form_for(@form, url: page_path, method: :post) do |form| %>
4
+ <%= render partial: 'form', object: form %>
5
+
6
+ <div class="actions">
7
+ <%= form.submit t(".save") %>
8
+ </div>
9
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <% content_for(:title, translated_attribute(@page.title)) %>
2
+ <div class="row column">
3
+ <div class="row">
4
+ <div class="columns medium-7 mediumlarge-8">
5
+ <div class="section">
6
+ <%== translated_attribute @page.body %>
7
+ </div>
8
+ </div>
9
+ </div>
10
+ </div>
11
+
12
+ <%= content_for :expanded do %>
13
+ <% if @page.commentable? %>
14
+ <%= comments_for @page, arguable: true %>
15
+ <% end %>
16
+ <% end %>
@@ -0,0 +1,4 @@
1
+ base_locale: en
2
+ locales: [en]
3
+ ignore_unused:
4
+ - "decidim.features.pages.name"
@@ -0,0 +1,19 @@
1
+ ca:
2
+ decidim:
3
+ features:
4
+ pages:
5
+ name: Pàgina
6
+ pages:
7
+ admin:
8
+ models:
9
+ components:
10
+ body: Cos
11
+ commentable: Habilitar comentaris per a aquesta pàgina
12
+ title: Títol
13
+ pages:
14
+ edit:
15
+ save: Desa la pàgina
16
+ title: Editar pàgina
17
+ update:
18
+ invalid: Hi ha hagut errors en desar la pàgina.
19
+ success: Pàgina guardada correctament.
@@ -0,0 +1,20 @@
1
+ ---
2
+ en:
3
+ decidim:
4
+ features:
5
+ pages:
6
+ name: Page
7
+ pages:
8
+ admin:
9
+ models:
10
+ components:
11
+ body: Body
12
+ commentable: Enable comments for this page
13
+ title: Title
14
+ pages:
15
+ edit:
16
+ save: Save page
17
+ title: Edit page
18
+ update:
19
+ invalid: There's been errors when saving the page.
20
+ success: Page saved successfully.
@@ -0,0 +1,19 @@
1
+ es:
2
+ decidim:
3
+ features:
4
+ pages:
5
+ name: Página
6
+ pages:
7
+ admin:
8
+ models:
9
+ components:
10
+ body: Cuerpo
11
+ commentable: Habilitar comentarios para esta página
12
+ title: Título
13
+ pages:
14
+ edit:
15
+ save: Guardar página
16
+ title: Editar página
17
+ update:
18
+ invalid: Ha habido errores al guardar la página.
19
+ success: Página guardada correctamente.
@@ -0,0 +1,11 @@
1
+ class CreateDecidimPages < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :decidim_pages_pages do |t|
4
+ t.jsonb :title
5
+ t.jsonb :body
6
+ t.references :decidim_feature, index: true
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddCommentableToPages < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :decidim_pages_pages, :commentable, :boolean, null: false, default: false
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require "decidim/pages/admin"
3
+ require "decidim/pages/engine"
4
+ require "decidim/pages/admin_engine"
5
+ require "decidim/pages/feature"
6
+
7
+ module Decidim
8
+ # This namespace holds the logic of the `Pages` component. This component
9
+ # allows the admins to create a custom page for a participatory process.
10
+ module Pages
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # This module contains all the domain logic associated to Decidim's Pages
5
+ # component admin panel.
6
+ module Admin
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # This is the admin interface for `decidim-pages`. It lets you edit and
5
+ # configure the page associated to a participatory process.
6
+ class AdminEngine < ::Rails::Engine
7
+ isolate_namespace Decidim::Pages::Admin
8
+
9
+ paths["db/migrate"] = nil
10
+
11
+ routes do
12
+ post "/", to: "pages#update", as: :page
13
+ root to: "pages#edit"
14
+ end
15
+
16
+ def load_seed
17
+ nil
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ module Pages
4
+ # This is the engine that runs on the public interface of `decidim-pages`.
5
+ # It mostly handles rendering the created page associated to a participatory
6
+ # process.
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace Decidim::Pages
9
+
10
+ routes do
11
+ root to: "application#show"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "decidim/features/namer"
4
+
5
+ Decidim.register_feature(:pages) do |feature|
6
+ feature.engine = Decidim::Pages::Engine
7
+ feature.admin_engine = Decidim::Pages::AdminEngine
8
+
9
+ feature.on(:create) do |instance|
10
+ Decidim::Pages::CreatePage.call(instance) do
11
+ on(:invalid) { raise "Can't create page" }
12
+ end
13
+ end
14
+
15
+ feature.on(:destroy) do |instance|
16
+ Decidim::Pages::DestroyPage.call(instance) do
17
+ on(:error) { raise "Can't destroy page" }
18
+ end
19
+ end
20
+
21
+ feature.seeds do
22
+ Decidim::ParticipatoryProcess.all.each do |process|
23
+ next unless process.steps.any?
24
+
25
+ feature = Decidim::Feature.create!(
26
+ name: Decidim::Features::Namer.new(process.organization.available_locales, :pages).i18n_name,
27
+ manifest_name: :pages,
28
+ participatory_process: process
29
+ )
30
+
31
+ Decidim::Pages::Page.create!(
32
+ feature: feature,
33
+ title: Decidim::Faker::Localized.sentence(2),
34
+ body: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
35
+ Decidim::Faker::Localized.paragraph(3)
36
+ end,
37
+ commentable: true
38
+ )
39
+ end
40
+ end
41
+ end
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decidim-pages
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josep Jaume Rey Peroy
8
+ - Marc Riera Casals
9
+ - Oriol Gual Oliva
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-12-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: decidim-core
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '='
27
+ - !ruby/object:Gem::Version
28
+ version: 0.0.1
29
+ - !ruby/object:Gem::Dependency
30
+ name: decidim-comments
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '='
34
+ - !ruby/object:Gem::Version
35
+ version: 0.0.1
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.0.1
43
+ - !ruby/object:Gem::Dependency
44
+ name: rectify
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 0.8.0
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 0.8.0
57
+ - !ruby/object:Gem::Dependency
58
+ name: decidim-dev
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '='
62
+ - !ruby/object:Gem::Version
63
+ version: 0.0.1
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '='
69
+ - !ruby/object:Gem::Version
70
+ version: 0.0.1
71
+ description: A pages component for decidim's participatory processes.
72
+ email:
73
+ - josepjaume@gmail.com
74
+ - mrc2407@gmail.com
75
+ - oriolgual@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - README.md
81
+ - Rakefile
82
+ - app/commands/decidim/pages/admin/update_page.rb
83
+ - app/commands/decidim/pages/create_page.rb
84
+ - app/commands/decidim/pages/destroy_page.rb
85
+ - app/controllers/decidim/pages/admin/application_controller.rb
86
+ - app/controllers/decidim/pages/admin/pages_controller.rb
87
+ - app/controllers/decidim/pages/application_controller.rb
88
+ - app/forms/decidim/pages/admin/page_form.rb
89
+ - app/helpers/decidim/pages/application_helper.rb
90
+ - app/models/decidim/pages/application_record.rb
91
+ - app/models/decidim/pages/page.rb
92
+ - app/views/decidim/pages/admin/pages/_form.html.erb
93
+ - app/views/decidim/pages/admin/pages/edit.html.erb
94
+ - app/views/decidim/pages/application/show.html.erb
95
+ - config/i18n-tasks.yml
96
+ - config/locales/ca.yml
97
+ - config/locales/en.yml
98
+ - config/locales/es.yml
99
+ - db/migrate/20161116121353_create_decidim_pages.rb
100
+ - db/migrate/20161214150429_add_commentable_to_pages.rb
101
+ - lib/decidim/pages.rb
102
+ - lib/decidim/pages/admin.rb
103
+ - lib/decidim/pages/admin_engine.rb
104
+ - lib/decidim/pages/engine.rb
105
+ - lib/decidim/pages/feature.rb
106
+ - lib/tasks/decidim/pages_tasks.rake
107
+ homepage: https://github.com/AjuntamentdeBarcelona/decidim
108
+ licenses:
109
+ - AGPLv3
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.3.1
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A pages component for decidim's participatory processes.
131
+ test_files: []