Class: YesView
Constant Summary
Yescode::Strings::SNAKE_CASE_REGEX
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
camel_case, class_name, filename, pascal_case, snake_case
#emote, #emote_cache, #file_cache
Class Attribute Details
.layout ⇒ Object
15
16
17
|
# File 'lib/yes_view.rb', line 15
def layout
@layout || "layout"
end
|
.logger ⇒ Object
Returns the value of attribute logger.
9
10
11
|
# File 'lib/yes_view.rb', line 9
def logger
@logger
end
|
.paths ⇒ Object
Returns the value of attribute paths.
9
10
11
|
# File 'lib/yes_view.rb', line 9
def paths
@paths
end
|
.template_name ⇒ Object
27
28
29
|
# File 'lib/yes_view.rb', line 27
def template_name
@template_name || "#{filename}.emote"
end
|
.template_path ⇒ Object
11
12
13
|
# File 'lib/yes_view.rb', line 11
def template_path
@template_path || File.join(".", "app", "views")
end
|
Instance Attribute Details
#ajax ⇒ Object
Returns the value of attribute ajax.
32
33
34
|
# File 'lib/yes_view.rb', line 32
def ajax
@ajax
end
|
#assets ⇒ Object
Returns the value of attribute assets.
32
33
34
|
# File 'lib/yes_view.rb', line 32
def assets
@assets
end
|
#csrf_name ⇒ Object
Returns the value of attribute csrf_name.
32
33
34
|
# File 'lib/yes_view.rb', line 32
def csrf_name
@csrf_name
end
|
#csrf_value ⇒ Object
Returns the value of attribute csrf_value.
32
33
34
|
# File 'lib/yes_view.rb', line 32
def csrf_value
@csrf_value
end
|
#session ⇒ Object
Returns the value of attribute session.
32
33
34
|
# File 'lib/yes_view.rb', line 32
def session
@session
end
|
Class Method Details
.template ⇒ Object
19
20
21
|
# File 'lib/yes_view.rb', line 19
def template
File.join(template_path, template_name)
end
|
.view(template_name) ⇒ Object
23
24
25
|
# File 'lib/yes_view.rb', line 23
def view(template_name)
@template_name = template_name
end
|
Instance Method Details
68
69
70
|
# File 'lib/yes_view.rb', line 68
def _form
"</form>"
end
|
#csrf_field ⇒ Object
54
55
56
|
# File 'lib/yes_view.rb', line 54
def csrf_field
"<input type=\"hidden\" name=\"#{csrf_name}\" value=\"#{csrf_value}\" />"
end
|
#css ⇒ Object
80
81
82
83
84
|
# File 'lib/yes_view.rb', line 80
def css
return [] unless assets
assets["css"].map { |filename| "/css/#{filename}" }
end
|
#fetch(class_name, method_name, params = {}) ⇒ Object
96
97
98
|
# File 'lib/yes_view.rb', line 96
def fetch(class_name, method_name, params = {})
"<div data-href=\"#{path(class_name, method_name, params)}\"></div>"
end
|
58
59
60
61
62
63
64
65
66
|
# File 'lib/yes_view.rb', line 58
def form(params = {})
params = { method: "post" }.merge(params)
attr_string = params.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
<<~HTML
<form #{attr_string}>
#{csrf_field}
HTML
end
|
72
73
74
75
76
77
78
|
# File 'lib/yes_view.rb', line 72
def form_link(str, controller_name, method_name, params = {})
<<~HTML
#{form(action: path(controller_name, method_name, params))}
<input type="submit" value="#{str}" />
#{_form}
HTML
end
|
#js ⇒ Object
86
87
88
89
90
|
# File 'lib/yes_view.rb', line 86
def js
return [] unless assets
assets["js"].map { |filename| "/js/#{filename}" }
end
|
#path(class_name, method_name, params = {}) ⇒ Object
92
93
94
|
# File 'lib/yes_view.rb', line 92
def path(class_name, method_name, params = {})
Object.const_get(:App).path(class_name, method_name, params)
end
|
#render(tmpl, params = {}) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/yes_view.rb', line 38
def render(tmpl, params = {})
case tmpl
when YesView
tmpl.csrf_name = csrf_name
tmpl.csrf_value = csrf_value
tmpl.session = session
tmpl.assets = assets
tmpl.ajax = ajax
emote(tmpl.template, params, tmpl)
when String
emote(tmpl, params)
else
raise StandardError, "Unsupported template type passed to render"
end
end
|
#template ⇒ Object
34
35
36
|
# File 'lib/yes_view.rb', line 34
def template
self.class.template
end
|