Sha256: 04e3ddc37fff366194ae49e3e029a0ec41d950096b4cd678172665718d4330f7

Contents?: true

Size: 962 Bytes

Versions: 5

Compression:

Stored size: 962 Bytes

Contents

module Puffer
  module Inputs
    class Base

      attr_accessor :builder, :template, :field

      def self.render *args
        new(*args).render
      end

      def initialize builder, field
        @builder = builder
        @field = field
        @template = builder.instance_variable_get :@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

5 entries across 5 versions & 1 rubygems

Version Path
puffer-0.0.23 lib/puffer/inputs/base.rb
puffer-0.0.22 lib/puffer/inputs/base.rb
puffer-0.0.21 lib/puffer/inputs/base.rb
puffer-0.0.20 lib/puffer/inputs/base.rb
puffer-0.0.19 lib/puffer/inputs/base.rb