Class: Sentiero::Web::Views::BaseView
- Inherits:
-
Object
- Object
- Sentiero::Web::Views::BaseView
show all
- Includes:
- Escaping, Formatting
- Defined in:
- lib/sentiero/web/views/base_view.rb
Direct Known Subclasses
AnalyticsIndexView, AnalyzerView, ClientErrorShowView, ConversionsView, EngagementView, ErrorsIndexView, EventShowView, EventsIndexView, ExportView, FormsView, FunnelView, HeatmapView, ImportView, PageReportView, ProblemShowView, SegmentsView, SessionShowView, SessionsIndexView
Constant Summary
collapse
- TEMPLATES_DIR =
File.expand_path("../templates", __dir__).freeze
- TEMPLATE_CACHE =
Concurrent::Map.new
Constants included
from Escaping
Escaping::HTML_UNSAFE_IN_SCRIPT, Escaping::HTML_UNSAFE_IN_SCRIPT_PATTERN
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Formatting
#format_duration, #format_vital, #parse_browser, #parse_device
Methods included from Escaping
#escape_html, #escape_js_string, #escape_json
Constructor Details
Returns a new instance of BaseView.
21
22
23
|
# File 'lib/sentiero/web/views/base_view.rb', line 21
def initialize
@base_path = ""
end
|
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
19
20
21
|
# File 'lib/sentiero/web/views/base_view.rb', line 19
def base_path
@base_path
end
|
#csrf_token ⇒ Object
Returns the value of attribute csrf_token.
19
20
21
|
# File 'lib/sentiero/web/views/base_view.rb', line 19
def csrf_token
@csrf_token
end
|
Class Method Details
.compiled_template(filename) ⇒ Object
60
61
62
63
64
|
# File 'lib/sentiero/web/views/base_view.rb', line 60
def self.compiled_template(filename)
TEMPLATE_CACHE.compute_if_absent(filename) do
ERB.new(File.read(File.join(TEMPLATES_DIR, filename)), trim_mode: "-")
end
end
|
Instance Method Details
#built_asset(name) ⇒ Object
#escape_js(text) ⇒ Object
27
|
# File 'lib/sentiero/web/views/base_view.rb', line 27
def escape_js(text) = escape_js_string(text)
|
#h(text) ⇒ Object
25
|
# File 'lib/sentiero/web/views/base_view.rb', line 25
def h(text) = escape_html(text)
|
#range_pairs ⇒ Object
Non-empty since/until query params, for range-preserving cross-links.
Available to any view exposing since/until_str accessors.
33
34
35
36
37
38
|
# File 'lib/sentiero/web/views/base_view.rb', line 33
def range_pairs
pairs = {}
pairs["since"] = since if since && !since.to_s.empty?
pairs["until"] = until_str if until_str && !until_str.to_s.empty?
pairs
end
|
#render ⇒ Object
44
45
46
|
# File 'lib/sentiero/web/views/base_view.rb', line 44
def render
render_with(template, view: self)
end
|
#render_layout(content, request_path:) ⇒ Object
56
57
58
|
# File 'lib/sentiero/web/views/base_view.rb', line 56
def render_layout(content, request_path:)
render_with("dashboard.html.erb", view: self, content: content, request_path: request_path)
end
|
#render_partial(filename, **locals) ⇒ Object
48
49
50
|
# File 'lib/sentiero/web/views/base_view.rb', line 48
def render_partial(filename, **locals)
render_with(filename, view: self, **locals)
end
|
#render_session_row(session, selectable, csrf_token = nil) ⇒ Object
52
53
54
|
# File 'lib/sentiero/web/views/base_view.rb', line 52
def render_session_row(session, selectable, csrf_token = nil)
render_partial("_session_row.html.erb", s: session, selectable: selectable, csrf_token: csrf_token)
end
|
#template ⇒ Object
40
41
42
|
# File 'lib/sentiero/web/views/base_view.rb', line 40
def template
raise NotImplementedError, "#{self.class} must define #template"
end
|