Module: Giter8::Renderer

Defined in:
lib/giter8/renderer/utils.rb,
lib/giter8/renderer/executor.rb

Overview

Module Renderer implements all mechanisms related to template rendering

Defined Under Namespace

Classes: Executor

Constant Summary collapse

WORD_ONLY_REGEXP =
/[^a-zA-Z0-9_]/.freeze
WORD_SPACE_REGEXP =
/[^a-zA-Z0-9]/.freeze
SNAKE_CASE_REGEXP =
/[\s.]/.freeze
ALPHABET =
((65..90).to_a + (97..122).to_a).map(&:chr).freeze
HELPERS =
{
  "upper" => method(:uppercase),
  "uppercase" => method(:uppercase),
  "lower" => method(:lowercase),
  "lowercase" => method(:lowercase),
  "cap" => method(:capitalize),
  "capitalize" => method(:capitalize),
  "decap" => method(:decapitalize),
  "decapitalize" => method(:decapitalize),
  "start" => method(:start_case),
  "start-case" => method(:start_case),
  "word" => method(:word_only),
  "word-only" => method(:word_only),
  "space" => method(:word_space),
  "word-space" => method(:word_space),
  "Camel" => method(:upper_camel),
  "upper-camel" => method(:upper_camel),
  "camel" => method(:lower_camel),
  "lower-camel" => method(:lower_camel),
  "hyphen" => method(:hyphenate),
  "hyphenate" => method(:hyphenate),
  "norm" => method(:normalize),
  "normalize" => method(:normalize),
  "snake" => method(:snake_case),
  "snake-case" => method(:snake_case),
  "package" => method(:package_naming),
  "package-naming" => method(:package_naming),
  "packaged" => method(:package_dir),
  "package-dir" => method(:package_dir),
  "random" => method(:random),
  "generate-random" => method(:random)
}.freeze

Class Method Summary collapse

Class Method Details

.capitalize(val) ⇒ Object



19
20
21
# File 'lib/giter8/renderer/utils.rb', line 19

def self.capitalize(val)
  val.capitalize
end

.decapitalize(val) ⇒ Object



23
24
25
# File 'lib/giter8/renderer/utils.rb', line 23

def self.decapitalize(val)
  lowercase(val)
end

.hyphenate(val) ⇒ Object



47
48
49
# File 'lib/giter8/renderer/utils.rb', line 47

def self.hyphenate(val)
  val.gsub(/\s/, "-")
end

.lower_camel(val) ⇒ Object



43
44
45
# File 'lib/giter8/renderer/utils.rb', line 43

def self.lower_camel(val)
  decapitalize(word_only(start_case(val)))
end

.lowercase(val) ⇒ Object



15
16
17
# File 'lib/giter8/renderer/utils.rb', line 15

def self.lowercase(val)
  val.downcase
end

.normalize(val) ⇒ Object



51
52
53
# File 'lib/giter8/renderer/utils.rb', line 51

def self.normalize(val)
  lowercase(hyphenate(val))
end

.package_dir(val) ⇒ Object



63
64
65
# File 'lib/giter8/renderer/utils.rb', line 63

def self.package_dir(val)
  val.gsub(/\./, "/")
end

.package_naming(val) ⇒ Object



59
60
61
# File 'lib/giter8/renderer/utils.rb', line 59

def self.package_naming(val)
  val.gsub(/\s/, ".")
end

.randomObject



67
68
69
# File 'lib/giter8/renderer/utils.rb', line 67

def self.random
  ALPHABET.sample(40).join
end

.snake_case(val) ⇒ Object



55
56
57
# File 'lib/giter8/renderer/utils.rb', line 55

def self.snake_case(val)
  val.gsub(SNAKE_CASE_REGEXP, "_")
end

.start_case(val) ⇒ Object



27
28
29
# File 'lib/giter8/renderer/utils.rb', line 27

def self.start_case(val)
  val.split.map(&:capitalize)
end

.upper_camel(val) ⇒ Object



39
40
41
# File 'lib/giter8/renderer/utils.rb', line 39

def self.upper_camel(val)
  word_only(start_case(val))
end

.uppercase(val) ⇒ Object



11
12
13
# File 'lib/giter8/renderer/utils.rb', line 11

def self.uppercase(val)
  val.upcase
end

.word_only(val) ⇒ Object



31
32
33
# File 'lib/giter8/renderer/utils.rb', line 31

def self.word_only(val)
  val.gsub(WORD_ONLY_REGEXP, "")
end

.word_space(val) ⇒ Object



35
36
37
# File 'lib/giter8/renderer/utils.rb', line 35

def self.word_space(val)
  val.gsub(WORD_SPACE_REGEXP, " ")
end