Module: WrapIt

Defined in:
lib/wrap_it/helpers.rb,
lib/wrap_it/base.rb,
lib/wrap_it/html.rb,
lib/wrap_it/link.rb,
lib/wrap_it/enums.rb,
lib/wrap_it/rails.rb,
lib/wrap_it/version.rb,
lib/wrap_it/no_rails.rb,
lib/wrap_it/sections.rb,
lib/wrap_it/switches.rb,
lib/wrap_it/arguments.rb,
lib/wrap_it/callbacks.rb,
lib/wrap_it/container.rb,
lib/wrap_it/html_data.rb,
lib/wrap_it/frameworks.rb,
lib/wrap_it/html_class.rb,
lib/wrap_it/capture_array.rb,
lib/wrap_it/text_container.rb,
lib/wrap_it/derived_attributes.rb

Overview

Registering helpers

To use your classes and helpers in templates you should register your library. First, in your framework initialization, you should register your library in WrapIt. You can have separate module for it or WrapIt will make anonymous one. After this, your module will have register and unregister methods to register your classes.

Examples:

usual case - library in separate module

# initialization time
module Library
  module Helpers; end
end
WrapIt.register_module Library::Helpers, prefix: 'lib_'

# controller
class MyController < ApplicationController
  helper Library::Helpers
end

# implementation
module Library
  module Helpers
    class Button < WrapIt::Base
      ...
    end

    register :super_button, Button
  end
end

# in template:
<%= lib_super_button 'text' %>

anonymous module

helpers = WrapIt.register_module prefix: 'lib_'

class Button < WrapIt::Base
  ...
end

helpers.register :super_button, Button

class MyController
  helper helpers
end

Author:

Defined Under Namespace

Modules: Arguments, Callbacks, CaptureArray, DerivedAttributes, Enums, HTML, Renderer, Sections, Switches, TextContainer Classes: Base, Container, HTMLClass, HTMLData, Link

Constant Summary collapse

VERSION =

Current gem version

'1.0.2'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_module(mod = nil, opts = {}) ⇒ void

This method returns an undefined value.

Registers helpers module

Options Hash (opts):

  • :prefix (String)

    prefix for helper methods



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/wrap_it/helpers.rb', line 62

def self.register_module(*args)
  options = args.extract_options!
  options.symbolize_keys!
  options = {prefix: ''}.merge(options)
  mod = args.shift
  mod.is_a?(Module) || mod = Module.new
  mod.instance_eval do
    define_singleton_method(:register, &WrapIt.register_block(options))
    define_singleton_method(:unregister, &WrapIt.unregister_block(options))
  end
  mod
end

Instance Method Details

#register([name, ...], class_name) ⇒ Object

adds to template list of helpers for creating elements of specified class



# File 'lib/wrap_it/helpers.rb', line 75