Class: Staticz::Compilable::Scss
Instance Attribute Summary collapse
Instance Method Summary
collapse
#build_path, #create_link_function, #exists?, included, #path, #path_method_name, #print, #source_path, #valid?
Constructor Details
#initialize(name, type:) ⇒ Scss
Returns a new instance of Scss.
12
13
14
15
16
|
# File 'lib/manifest/compilable/scss.rb', line 12
def initialize(name, type:)
@name = name
@warnings = []
@type = type
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/manifest/compilable/scss.rb', line 10
def name
@name
end
|
Instance Method Details
#build(listener_class: nil) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/manifest/compilable/scss.rb', line 30
def build(listener_class: nil)
listener = listener_class&.new(self)
if valid?
File.write build_path, render
listener&.finish
else
listener&.error
end
end
|
#build_file_ending ⇒ Object
22
23
24
|
# File 'lib/manifest/compilable/scss.rb', line 22
def build_file_ending
"css"
end
|
#debug(message, options) ⇒ Object
62
63
64
|
# File 'lib/manifest/compilable/scss.rb', line 62
def debug(message, options)
warn(message, debug)
end
|
#errors ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/manifest/compilable/scss.rb', line 46
def errors
@_errors_cache ||= begin
errors = super
if exists?
begin
Sass.compile(source_path, style: :compressed, logger: Sass::Logger.silent).css
rescue => e
errors << e.message
end
end
errors
end
end
|
#file_type_name ⇒ Object
26
27
28
|
# File 'lib/manifest/compilable/scss.rb', line 26
def file_type_name
@type.capitalize
end
|
#render ⇒ Object
42
43
44
|
# File 'lib/manifest/compilable/scss.rb', line 42
def render
Sass.compile(source_path, style: :compressed, logger: Sass::Logger.silent).css
end
|
#source_file_ending ⇒ Object
18
19
20
|
# File 'lib/manifest/compilable/scss.rb', line 18
def source_file_ending
@type
end
|
#warn(message, options) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/manifest/compilable/scss.rb', line 66
def warn(message, options)
pastel = Pastel.new
line = options.span.start.line + 1
start_index = options.span.start.column
end_index = options.span.end.column
@warnings << <<~WARNING
#{pastel.yellow.bold("Warning")}: #{message}
#{" " * line.to_s.size} #{pastel.blue("╷")}
#{pastel.blue(line)} #{pastel.blue("│")} #{pastel.red(options.span.context.strip)}
#{" " * line.to_s.size} #{pastel.blue("│")} #{" " * start_index}#{pastel.red("^" * (end_index - start_index))}
#{" " * line.to_s.size} #{pastel.blue("╵")}
#{options.stack}
WARNING
end
|
#warnings ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/manifest/compilable/scss.rb', line 85
def warnings
if valid?
Sass.compile(source_path, style: :compressed, logger: self)
end
@warnings
end
|