Sha256: 230fbc6de6c3e211e0b3ce3fc1e7175367a28ff6fb60913e0ad7036cecbbe726

Contents?: true

Size: 875 Bytes

Versions: 11

Compression:

Stored size: 875 Bytes

Contents

module Puffer
  module Inputs
    class Base

      attr_accessor :builder, :template, :field

      def initialize builder, template, field
        @builder = builder
        @field = field
        @template = template
      end

      def render
        html.html_safe
      end

      def html
        <<-INPUT
          <div class="label">
            #{label}
            <div class="field_error">
              #{error}
            </div>
          </div>
          #{input}
        INPUT
      end

      def label
        builder.label field
      end

      def input
        builder.text_field field, field.input_options
      end

      def error
        builder.object.errors[field.name.to_sym].first
      end

      def method_missing method, *args, &block
        template.send method, *args, &block if template.respond_to? method
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
puffer-0.0.18 lib/puffer/inputs/base.rb
puffer-0.0.17 lib/puffer/inputs/base.rb
puffer-0.0.16 lib/puffer/inputs/base.rb
puffer-0.0.15 lib/puffer/inputs/base.rb
puffer-0.0.14 lib/puffer/inputs/base.rb
puffer-0.0.13 lib/puffer/inputs/base.rb
puffer-0.0.12 lib/puffer/inputs/base.rb
puffer-0.0.11 lib/puffer/inputs/base.rb
puffer-0.0.10 lib/puffer/inputs/base.rb
puffer-0.0.9 lib/puffer/inputs/base.rb
puffer-0.0.8 lib/puffer/inputs/base.rb