Module: Shi::Args::Value
- Extended by:
- Tools
- Defined in:
- lib/shi/args/values.rb
Defined Under Namespace
Constant Summary collapse
- UNITS =
%i[ % cm mm Q in pc pt px em ex ch rem lh rlh vw vh vmin vmax vb vi svw svh lvw lvh dvw dvh ]
- UNITS_PART =
'(' + UNITS.map { |s| s.to_s }.join('|') + ')'
- PATTERN_TRUE =
'true'
- PATTERN_FALSE =
'false'
- PATTERN_NIL =
'nil'
- PATTERN_VARIABLE =
/^\{\{\-?\s+(?<variable>[a-zA-Z_][\w\.]*)\s+\-?\}\}$/
- PATTERN_LINK =
/^@(?<path>.*)$/
- PATTERN_COLOR =
/^(?<color>#\h+)$/
- PATTERN_INTEGER =
/^(?<number>\d+)$/
- PATTERN_FLOAT =
/^(?<number>\d*\.\d+)$/
- PATTERN_INTEGER_MEASURE =
Regexp.compile '^(?<number>\d+)(?<unit>' + UNITS_PART + ')$'
- PATTERN_FLOAT_MEASURE =
Regexp.compile '^(?<number>\d*\.\d+)(?<unit>' + UNITS_PART + ')$'
Class Method Summary collapse
Class Method Details
.lookup_file(context, path) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/shi/args/values.rb', line 125 def lookup_file context, path site = context.registers[:site] relative_path = Liquid::Template.parse(path.strip).render(context) relative_path_with_leading_slash = Jekyll::PathManager.join('', relative_path) site.static_files.each do |item| return item if item.relative_path == relative_path return item if item.relative_path == relative_path_with_leading_slash end raise ArgumentError, "Couldn't find file: #{relative_path}" end |
.parse(context, value) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/shi/args/values.rb', line 181 def parse context, value value = value.strip case value when PATTERN_TRUE true when PATTERN_FALSE false when PATTERN_NIL nil when PATTERN_VARIABLE context[$~[:variable]] when PATTERN_LINK lookup_file context, unquote($~[:path]) when PATTERN_COLOR Shi::Args::Value::Color::new $~[:color] when PATTERN_INTEGER $~[:number].to_i when PATTERN_FLOAT $~[:number].to_f when PATTERN_INTEGER_MEASURE Shi::Args::Value::Measure::new value, $~[:number].to_i, $~[:unit] when PATTERN_FLOAT_MEASURE Shi::Args::Value::Measure::new value, $~[:number].to_f, $~[:unit] else unquote value end end |