Sha256: 0760017303db682c41632c826891c264d4843018445b0ed9cc01f292b7889da4

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 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!(organization: organization, slug: slug) do |page|
            page.title = localized_attribute(slug, :title)
            page.content = localized_attribute(slug, :content)
          end
        end
      end

      private

      attr_reader :organization

      def localized_attribute(slug, attribute)
        Decidim.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

14 entries across 14 versions & 1 rubygems

Version Path
decidim-system-0.15.2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.15.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.15.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.14.4 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.14.3 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.14.2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.14.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.13.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.12.2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.13.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.12.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.13.0.pre1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.12.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.12.0.pre app/commands/decidim/system/create_default_pages.rb