Module: Staticz::Compilable

Included in:
Cs, Haml, Js, React, Scss, SimpleFile, Slim
Defined in:
lib/manifest/compilable.rb,
lib/manifest/compilable/cs.rb,
lib/manifest/compilable/js.rb,
lib/manifest/compilable/haml.rb,
lib/manifest/compilable/scss.rb,
lib/manifest/compilable/slim.rb,
lib/manifest/compilable/react.rb,
lib/manifest/compilable/simple_file.rb

Defined Under Namespace

Modules: ClassMethods Classes: Cs, Haml, Js, React, Scss, SimpleFile, Slim

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/manifest/compilable.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#build_pathObject



33
34
35
# File 'lib/manifest/compilable.rb', line 33

def build_path
  "build/#{name}.#{build_file_ending}"
end


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

def create_link_function
  link_path = "/#{name}.#{build_file_ending}"
  shortened_link_path = "/#{name}"

  Object.send(:define_method, path_method_name) do |shorten: false|
    if shorten
      shortened_link_path
    else
      link_path
    end
  end
  Manifest.instance.functions << path_method_name
end

#errorsObject



53
54
55
56
57
58
59
# File 'lib/manifest/compilable.rb', line 53

def errors
  errors = []

  errors << "File does not exist" if !exists?

  errors
end

#exists?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/manifest/compilable.rb', line 37

def exists?
  File.exist? source_path
end

#pathObject



25
26
27
# File 'lib/manifest/compilable.rb', line 25

def path
  name.to_s
end

#path_method_nameObject



41
42
43
# File 'lib/manifest/compilable.rb', line 41

def path_method_name
  "#{path.gsub(/[^A-Za-z0-9]+/, "_").downcase}_path"
end


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/manifest/compilable.rb', line 75

def print(indentation, *args)
  valid_symbol = if valid?
    if warnings.any?
      Colors.in_yellow("")
    else
      Colors.in_green("")
    end
  else
    Colors.in_red("")
  end

  compilable_string = "#{" " * (indentation * 3)}└─ #{file_type_name}: #{path} #{valid_symbol}"
  compilable_string << " -> #{path_method_name}" if !args.include? :no_path

  puts compilable_string

  _height, width = IO.console&.winsize || [0, 20]

  errors.each do |full_error|
    line_width = width - (indentation * 3) - 3
    multiline_errors = full_error.scan(/.{1,#{line_width}}/)
    multiline_errors.each do |error|
      puts "#{" " * (indentation * 3)}   #{Colors.in_red(error)}"
    end
  end

  warnings.each do |warning|
    warning.lines.each do |line|
      puts "#{" " * (indentation * 3)}   #{line}"
    end
  end
end

#source_pathObject



29
30
31
# File 'lib/manifest/compilable.rb', line 29

def source_path
  "src/#{name}.#{source_file_ending}"
end

#valid?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/manifest/compilable.rb', line 45

def valid?
  errors.empty?
end

#warningsObject



49
50
51
# File 'lib/manifest/compilable.rb', line 49

def warnings
  []
end