Sha256: 11db101d457d7ac414d3bbe53ea389db3a35a79a3791a43eac79a8e4d54a24d7

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

module Vedeu

  module Templating

    # Provide helpers to be used with your Vedeu templates.
    #
    module Helpers

      # @param value [String] The HTML/CSS colour.
      # @param block [Proc]
      # @raise [Vedeu::Error::RequiresBlock]
      # @return [Vedeu::Views::Stream]
      def background(value, &block)
        define_stream(background: value, &block)
      end
      alias_method :bg, :background

      # @param attributes [Hash]
      # @option attributes foreground [String] The HTML/CSS foreground
      #   colour.
      # @option attributes background [String] The HTML/CSS background
      #   colour.
      # @param block [Proc]
      # @raise [Vedeu::Error::RequiresBlock]
      # @return [Vedeu::Views::Stream]
      def colour(attributes = {}, &block)
        define_stream(attributes, &block)
      end

      # @param value [String] The HTML/CSS colour.
      # @param block [Proc]
      # @raise [Vedeu::Error::RequiresBlock]
      # @return [Vedeu::Views::Stream]
      def foreground(value, &block)
        define_stream(foreground: value, &block)
      end
      alias_method :fg, :foreground

      # @param value [Symbol]
      # @param block [Proc]
      # @return [Vedeu::Views::Stream]
      def style(value, &block)
        define_stream(style: value, &block)
      end

      private

      # @see Vedeu::Templating::Helpers#colour
      def define_stream(attributes = {}, &block)
        fail Vedeu::Error::RequiresBlock unless block_given?

        encode(
          Vedeu::Views::Stream.build(
            colour: Vedeu::Colours::Colour.new(attributes),
            style:  Vedeu::Presentation::Style.new(attributes[:style]),
            value:  block.call))
      end

      # @param data [String]
      # @return [String]
      def encode(data)
        Vedeu::Templating::Encoder.process(data)
      end

    end # Helpers

  end # Templating

end # Vedeu

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vedeu-0.6.20 lib/vedeu/templating/helpers.rb
vedeu-0.6.19 lib/vedeu/templating/helpers.rb
vedeu-0.6.18 lib/vedeu/templating/helpers.rb
vedeu-0.6.17 lib/vedeu/templating/helpers.rb
vedeu-0.6.16 lib/vedeu/templating/helpers.rb
vedeu-0.6.15 lib/vedeu/templating/helpers.rb
vedeu-0.6.14 lib/vedeu/templating/helpers.rb
vedeu-0.6.13 lib/vedeu/templating/helpers.rb