Sha256: aad027b49cadd5cb520fa5395b0b9170e3535a52302b40f05e7c8d8c88b83ea1

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true
module Decidim
  module System
    # A command with all the business logic when creating a new organization in
    # the system. It creates the organization and invites the admin to the
    # system.
    class CreateDefaultPages < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(organization)
        @organization = organization
      end

      # Executes the command.
      #
      # Returns nothing.
      def call
        Decidim::StaticPage::DEFAULT_PAGES.map do |slug|
          Decidim::StaticPage.find_or_create_by!(slug: slug) do |page|
            page.organization = organization
            page.title = localized_attribute(slug, :title)
            page.content = localized_attribute(slug, :content)
          end
        end
      end

      private

      attr_reader :organization

      def localized_attribute(slug, attribute)
        I18n.available_locales.inject({}) do |result, locale|
          text = I18n.with_locale(locale) do
            I18n.t(attribute, scope: "decidim.system.default_pages.placeholders", page: slug)
          end

          result.update(locale => text)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
decidim-system-0.1.0 app/commands/decidim/system/create_default_pages.rb
decidim-0.1.0 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.0.8.1 app/commands/decidim/system/create_default_pages.rb
decidim-0.0.8.1 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.0.7 app/commands/decidim/system/create_default_pages.rb
decidim-0.0.7 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.0.6 app/commands/decidim/system/create_default_pages.rb
decidim-0.0.6 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.0.5 app/commands/decidim/system/create_default_pages.rb
decidim-0.0.5 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-0.0.4 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.0.3 app/commands/decidim/system/create_default_pages.rb
decidim-0.0.3 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.0.2 app/commands/decidim/system/create_default_pages.rb
decidim-0.0.2 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.0.1 app/commands/decidim/system/create_default_pages.rb
decidim-0.0.1 decidim-system/app/commands/decidim/system/create_default_pages.rb