Class: Humid
- Inherits:
-
Object
show all
- Defined in:
- lib/humid.rb,
lib/humid/version.rb,
lib/humid/log_subscriber.rb,
lib/humid/controller_runtime.rb
Defined Under Namespace
Modules: ControllerRuntime
Classes: FileNotFound, LogSubscriber, RenderError
Constant Summary
collapse
- VERSION =
"0.1.0".freeze
- @@context =
nil
Class Method Summary
collapse
Class Method Details
26
27
28
|
# File 'lib/humid.rb', line 26
def configure
yield config
end
|
.context ⇒ Object
54
55
56
|
# File 'lib/humid.rb', line 54
def context
@@context
end
|
.create_context ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/humid.rb', line 65
def create_context
ctx = MiniRacer::Context.new(**config.context_options)
if logger
ctx.attach("console.log", proc { |err| logger.debug(err.to_s) })
ctx.attach("console.info", proc { |err| logger.info(err.to_s) })
ctx.attach("console.error", proc { |err| logger.error(err.to_s) })
ctx.attach("console.warn", proc { |err| logger.warn(err.to_s) })
end
js = ""
js << remove_functions
js << renderer
ctx.eval(js)
source_path = config.application_path
map_path = config.source_map_path
if map_path
ctx.attach("readSourceMap", proc { File.read(map_path) })
end
filename = File.basename(source_path.to_s)
@@current_filename = filename
ctx.eval(File.read(source_path), filename: filename)
@@context = ctx
end
|
.dispose ⇒ Object
58
59
60
61
62
63
|
# File 'lib/humid.rb', line 58
def dispose
if @@context
@@context.dispose
@@context = nil
end
end
|
.logger ⇒ Object
41
42
43
|
# File 'lib/humid.rb', line 41
def logger
config.logger
end
|
.remove_functions ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/humid.rb', line 30
def remove_functions
" delete this.setTimeout;\n delete this.setInterval;\n delete this.clearTimeout;\n delete this.clearInterval;\n delete this.setImmediate;\n delete this.clearImmediate;\n JS\nend\n"
|
.render(*args) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/humid.rb', line 94
def render(*args)
ActiveSupport::Notifications.instrument("render.humid") do
context.call("__renderer", *args)
rescue MiniRacer::RuntimeError => e
message = ([e.message] + e.backtrace.filter { |x| x.starts_with? "JavaScript" }).join("\n")
render_error = Humid::RenderError.new(message)
if config.raise_render_errors
raise render_error
else
config.logger.error(render_error.inspect)
""
end
end
end
|
.renderer ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/humid.rb', line 45
def renderer
" var __renderer;\n function setHumidRenderer(fn) {\n __renderer = fn;\n }\n JS\nend\n"
|