Sha256: e6501e310629e6f49f97106edce52cf0cd4b7e689c1c6429875b5622a4ed6436

Contents?: true

Size: 1.25 KB

Versions: 21

Compression:

Stored size: 1.25 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)
            page.show_in_footer = true
          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

21 entries across 21 versions & 1 rubygems

Version Path
decidim-system-0.23.6 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.23.5 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.23.4 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.23.3 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.23.2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.23.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.23.1.rc1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.23.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.22.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.21.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.20.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.20.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.19.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.18.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.19.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.17.2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.18.0 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.17.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.16.1 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.17.0 app/commands/decidim/system/create_default_pages.rb