Sha256: bef3265d07c19e7eebbab202f90a102e43cbd62c13327651ae1657cabdee01ef

Contents?: true

Size: 776 Bytes

Versions: 5

Compression:

Stored size: 776 Bytes

Contents

require 'hanami/utils/string'

module Hanami
  module View
    module Rendering
      # @since 0.2.0
      class TemplateName
        NAMESPACE_SEPARATOR = '::'.freeze

        def initialize(name, namespace)
          @name = name
          compile!(namespace)
        end

        def to_s
          @name
        end

        private
        def compile!(namespace)
          tokens(namespace) {|token| replace!(token) }
          @name = Utils::String.new(@name).underscore
        end

        def tokens(namespace)
          namespace.to_s.split(NAMESPACE_SEPARATOR).each do |token|
            yield token
          end
        end

        def replace!(token)
          @name.gsub!(%r{\A#{ token }#{ NAMESPACE_SEPARATOR }}, '')
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hanami-view-1.0.0.beta1 lib/hanami/view/rendering/template_name.rb
hanami-view-0.8.0 lib/hanami/view/rendering/template_name.rb
hanami-view-0.7.0 lib/hanami/view/rendering/template_name.rb
hanami-view-0.6.1 lib/hanami/view/rendering/template_name.rb
hanami-view-0.6.0 lib/hanami/view/rendering/template_name.rb