Sha256: be8f4cf3d125255c129e672c65f8b877200c39a19cf20b2d4348a39d48f365e6

Contents?: true

Size: 1.23 KB

Versions: 18

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

18 entries across 18 versions & 2 rubygems

Version Path
decidim-system-0.4.4 app/commands/decidim/system/create_default_pages.rb
decidim-0.4.4 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.4.3 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.4.2 app/commands/decidim/system/create_default_pages.rb
decidim-system-0.4.1 app/commands/decidim/system/create_default_pages.rb
decidim-0.4.3 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-0.4.2 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-0.4.1 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.4.0 app/commands/decidim/system/create_default_pages.rb
decidim-0.4.0 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.3.2 app/commands/decidim/system/create_default_pages.rb
decidim-0.3.2 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.3.1 app/commands/decidim/system/create_default_pages.rb
decidim-0.3.1 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.3.0 app/commands/decidim/system/create_default_pages.rb
decidim-0.3.0 decidim-system/app/commands/decidim/system/create_default_pages.rb
decidim-system-0.2.0 app/commands/decidim/system/create_default_pages.rb
decidim-0.2.0 decidim-system/app/commands/decidim/system/create_default_pages.rb