Sha256: 12f27c1ab53e931f45fadc072a555c10896273b513c5bbecffe612113b4e3cf8

Contents?: true

Size: 1.09 KB

Versions: 26

Compression:

Stored size: 1.09 KB

Contents

module DynamicScaffold
  class Title
    attr_writer :name

    def initialize(config)
      @config = config
      @titles_cache = {}
      @name = @config.model.model_name.human
    end

    def name(&block)
      if block_given?
        @block = block
      elsif !@block.nil?
        @config.controller.view_context.instance_exec(&@block)
      else
        @name
      end
    end

    def current
      public_send(@config.controller.params[:action])
    end

    def index
      titles(:index)
    end

    def edit
      titles(:edit)
    end

    def new
      titles(:new)
    end

    def update
      titles(:edit)
    end

    def create
      titles(:new)
    end

    private

      def titles(action)
        unless @titles_cache[action]
          titles = OpenStruct.new
          titles.name = name
          titles.full = I18n.t("dynamic_scaffold.title.full.#{action}", name: titles.name)
          titles.action = I18n.t("dynamic_scaffold.title.action.#{action}")
          titles.freeze
          @titles_cache[action] = titles
        end

        @titles_cache[action]
      end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
dynamic_scaffold-1.12.2 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.12.1 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.12.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.11.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.10.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.9.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.8.1 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.8.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.7.1 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.7.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.6.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.5.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.4.3 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.4.2 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.4.1 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.4.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.3.0 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.2.2 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.2.1 lib/dynamic_scaffold/title.rb
dynamic_scaffold-1.2.0 lib/dynamic_scaffold/title.rb