module Eggshell::BlockHandler::BlockParams

Block parameters are default parameters given to a block type (e.g. setting a class). The parameters should be a map. Any keys are allowed, but for HTML, the standard keys that blocks will generally use are:

This module has pre-filled methods to make it is to drop in the functionality wherever it's needed. The assumption is that {{@vars}} is a hash.

Constants

ATTRIBUTES
CLASS
ID
KEYS
STYLE

Public Instance Methods

get_block_params(name, params = {}) click to toggle source

Gets the block params for a block type, merging in any defaults with the passed in parameters.

For the key {{ATTRIBUTES}}, individual keys within that are compared to the default param's {{ATTRIBUTES}}.

# File lib/eggshell/block-handler.rb, line 128
def get_block_params(name, params = {})
        params = {} if !params.is_a?(Hash)
        bparams = @vars[:block_params][name]
        if bparams
                bparams.each do |key, val|
                        if key == ATTRIBUTES
                                if !params[key].is_a?(Hash)
                                        params[key] = val
                                else
                                        val.each do |akey, aval|
                                                if !params[key].has_key?(akey)
                                                        params[key][akey] = aval
                                                end
                                        end
                                end
                        elsif !params.has_key?(key)
                                params[key] = val
                        end
                end
        end
        params
end
set_block_params(name, params) click to toggle source

Sets the default parameters for a block type.

# File lib/eggshell/block-handler.rb, line 118
def set_block_params(name, params)
        params = {} if !params.is_a?(Hash)
        @vars[:block_params][name] = params
end