Sha256: 17b25064ab6b9ec9726f4e55b0de8018219c737209f2797f8c67edaf54df6f0c

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Vedeu

  module Templating

    # Extend Template to provide client application view specific parsing.
    #
    class ViewTemplate < Template

      include Vedeu::Common
      include Vedeu::Templating::Helpers

      # @return [Vedeu::Lines]
      def parse
        lines_collection = Vedeu::Lines.new

        lines.each do |line|
          line_object = Vedeu::Line.new

          streams_for(line).each do |stream|
            next unless present?(stream)

            line_object << if stream =~ /({{)|(}})/
                             Vedeu::Templating::Decoder.process(stream)

                           else
                             Vedeu::Stream.new(value: stream)

                           end
          end

          lines_collection << line_object
        end

        lines_collection
      end

      protected

      # @!attribute [r] object
      # @return [Class]
      attr_reader :object

      # @!attribute [r] options
      # @return [Hash]
      attr_reader :options

      private

      # @param line [String]
      # @return [Array<String>]
      def streams_for(line)
        line.split(/({{.*}})/)
      end

      # @return [Array<String>]
      def lines
        content.lines.map(&:chomp)
      end

      # @return [String]
      def content
        ERB.new(load, nil, '-').result(binding)
      end

    end # ViewTemplate

  end # Templating

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.5.0 lib/vedeu/templating/view_template.rb