Module: Eggshell::BlockHandler::BlockParams

Overview

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:

  • {CLASS}: string

  • {ID}: string

  • {STYLE}: string or map of styles.

  • {ATTRIBUTES}: map of extra tag attributes.

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.

Constant Summary collapse

CLASS =
'class'
ID =
'id'
STYLE =
'style'
ATTRIBUTES =
'attributes'
KEYS =
[CLASS, ID, STYLE, ATTRIBUTES].freeze

Instance Method Summary collapse

Instance Method Details

#get_block_params(name, params = {}) ⇒ Object

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}.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/eggshell/block-handler.rb', line 122

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) ⇒ Object

Sets the default parameters for a block type.



112
113
114
115
# File 'lib/eggshell/block-handler.rb', line 112

def set_block_params(name, params)
	params = {} if !params.is_a?(Hash)
	@vars[:block_params][name] = params
end