card-mod-format 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/card/format/css_format.rb +17 -0
- data/lib/card/format/csv_format.rb +19 -0
- data/lib/card/format/data_format.rb +6 -0
- data/lib/card/format/file_format.rb +8 -0
- data/lib/card/format/html_format.rb +45 -0
- data/lib/card/format/js_format.rb +17 -0
- data/lib/card/format/json_format.rb +24 -0
- data/lib/card/format/rss_format.rb +9 -0
- data/lib/card/format/text_format.rb +16 -0
- data/lib/card/format/xml_format.rb +13 -0
- data/lib/card/path.rb +127 -0
- data/set/all/active_card.rb +6 -0
- data/set/all/base.rb +137 -0
- data/set/all/css.rb +37 -0
- data/set/all/csv.rb +93 -0
- data/set/all/error.rb +79 -0
- data/set/all/export.rb +68 -0
- data/set/all/file.rb +9 -0
- data/set/all/frame.rb +53 -0
- data/set/all/haml.rb +75 -0
- data/set/all/head.rb +148 -0
- data/set/all/header.rb +62 -0
- data/set/all/header/header_wrap.haml +4 -0
- data/set/all/html_content.rb +168 -0
- data/set/all/html_content/labeled.haml +4 -0
- data/set/all/html_error.rb +193 -0
- data/set/all/html_error/debug_server_error.haml +1015 -0
- data/set/all/html_error/not_found.haml +7 -0
- data/set/all/html_error/server_error.haml +5 -0
- data/set/all/html_show.rb +53 -0
- data/set/all/html_title.rb +47 -0
- data/set/all/html_wrapper.rb +159 -0
- data/set/all/js.rb +10 -0
- data/set/all/json.rb +166 -0
- data/set/all/links.rb +149 -0
- data/set/all/menu.rb +129 -0
- data/set/all/meta_tags.haml +4 -0
- data/set/all/path.rb +78 -0
- data/set/all/rich_html.rb +4 -0
- data/set/all/rss.rb +76 -0
- data/set/all/text.rb +7 -0
- data/set/self/home.rb +9 -0
- data/set/type/html.rb +27 -0
- data/set/type/json.rb +41 -0
- data/set/type/number.rb +22 -0
- data/set/type/phrase.rb +5 -0
- data/set/type/plain_text.rb +9 -0
- data/set/type/toggle.rb +38 -0
- data/set/type/uri.rb +15 -0
- metadata +123 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
format :html do
|
2
|
+
def show view, args
|
3
|
+
capture_the_freak do
|
4
|
+
content = send show_method, view, args
|
5
|
+
show_full_page? ? wrap_with_html_page(content) : content
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def show_method
|
10
|
+
"show_#{show_layout? ? :with : :without}_page_layout"
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_without_page_layout view, args
|
14
|
+
@main = true if params[:is_main] || args[:main]
|
15
|
+
args.delete(:layout)
|
16
|
+
view ||= args[:home_view] || :open # default_nest_view
|
17
|
+
render! view, args
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_full_page?
|
21
|
+
!Env.ajax?
|
22
|
+
end
|
23
|
+
|
24
|
+
wrapper :html_page do
|
25
|
+
<<-HTML.strip_heredoc
|
26
|
+
<!DOCTYPE HTML>
|
27
|
+
<html class="h-100">
|
28
|
+
<head>
|
29
|
+
#{head_content}
|
30
|
+
</head>
|
31
|
+
#{interior}
|
32
|
+
</html>
|
33
|
+
HTML
|
34
|
+
end
|
35
|
+
|
36
|
+
def head_content
|
37
|
+
nest card.rule_card(:head), view: :head_content
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# this is a temporary fix to try to debug a recurring encoding-related error
|
43
|
+
# TODO: remove the following after tracking down wikirate encoding bug
|
44
|
+
def capture_the_freak
|
45
|
+
yield
|
46
|
+
rescue Card::Error::ServerError => e
|
47
|
+
if e.message.match?(/invalid byte sequence/)
|
48
|
+
Card::Lexicon.cache.reset
|
49
|
+
Rails.logger.info "reset name cache to prevent encoding freakiness"
|
50
|
+
end
|
51
|
+
raise e
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
format do
|
2
|
+
view :title, compact: true, perms: :none do
|
3
|
+
standard_title
|
4
|
+
end
|
5
|
+
|
6
|
+
def standard_title
|
7
|
+
name_variant title_in_context(voo.title)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
format :html do
|
12
|
+
view :title do
|
13
|
+
show_view?(:title_link, :hide) ? render_title_link : render_title_no_link
|
14
|
+
end
|
15
|
+
|
16
|
+
view :title_link, compact: true, perms: :none do
|
17
|
+
link_to_card card.name, render_title_no_link
|
18
|
+
end
|
19
|
+
|
20
|
+
view :title_no_link, compact: true, perms: :none do
|
21
|
+
wrapped_title standard_title
|
22
|
+
end
|
23
|
+
|
24
|
+
def title_with_link link_text
|
25
|
+
link_to_card card.name, link_text
|
26
|
+
end
|
27
|
+
|
28
|
+
def safe_name
|
29
|
+
h super
|
30
|
+
end
|
31
|
+
|
32
|
+
def title_in_context title=nil
|
33
|
+
title = title&.html_safe
|
34
|
+
# escape titles generated from card names, but not those set explicitly
|
35
|
+
h super(title)
|
36
|
+
end
|
37
|
+
|
38
|
+
def wrapped_title title
|
39
|
+
wrap_with :span, class: classy("card-title"), title: title do
|
40
|
+
title.to_name.parts.join wrapped_joint
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def wrapped_joint
|
45
|
+
wrap_with :span, "+", classy("joint")
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
format :html do
|
2
|
+
# Does two main things:
|
3
|
+
# (1) gives CSS classes for styling and
|
4
|
+
# (2) adds card data for javascript - including the "card-slot" class,
|
5
|
+
# which in principle is not supposed to be in styles
|
6
|
+
def wrap slot=true, slot_attr={}, tag=:div, &block
|
7
|
+
attrib = slot_attributes slot, slot_attr
|
8
|
+
method_wrap :wrap_with, tag, attrib, &block
|
9
|
+
end
|
10
|
+
|
11
|
+
wrapper :slot do |opts|
|
12
|
+
class_up "card-slot", opts[:class] if opts[:class]
|
13
|
+
attrib = slot_attributes true, opts
|
14
|
+
method_wrap(:wrap_with, :div, attrib) { interior }
|
15
|
+
end
|
16
|
+
|
17
|
+
def haml_wrap slot=true, slot_attr={}, tag=:div, &block
|
18
|
+
attrib = slot_attributes slot, slot_attr
|
19
|
+
method_wrap :haml_tag, tag, attrib, &block
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_wrap method, tag, attrib, &block
|
23
|
+
@slot_view = @current_view
|
24
|
+
debug_slot { send method, tag, attrib, &block }
|
25
|
+
end
|
26
|
+
|
27
|
+
def slot_attributes slot, slot_attr
|
28
|
+
{ id: slot_id, class: wrap_classes(slot), data: wrap_data }.tap do |hash|
|
29
|
+
add_class hash, slot_attr.delete(:class)
|
30
|
+
hash.deep_merge! slot_attr
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def slot_id
|
35
|
+
"#{card.name.safe_key}-#{@current_view}-view"
|
36
|
+
end
|
37
|
+
|
38
|
+
def wrap_data slot=true
|
39
|
+
with_slot_data slot do
|
40
|
+
{ "card-id": card.id, "card-name": slot_cardname, "slot-id": SecureRandom.hex(10) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def slot_cardname
|
45
|
+
name = card.name
|
46
|
+
name = card.new? && name.compound? ? name.url_key : name
|
47
|
+
h name
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_slot_data slot
|
51
|
+
hash = yield
|
52
|
+
# rails helper convert slot hash to json
|
53
|
+
# but haml joins nested keys with a dash
|
54
|
+
hash[:slot] = slot_options_json if slot
|
55
|
+
hash
|
56
|
+
end
|
57
|
+
|
58
|
+
def slot_options_json
|
59
|
+
html_escape_except_quotes JSON(slot_options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def slot_options
|
63
|
+
options = voo ? voo.slot_options : {}
|
64
|
+
name_context_slot_option options
|
65
|
+
options
|
66
|
+
end
|
67
|
+
|
68
|
+
def name_context_slot_option opts
|
69
|
+
return unless initial_context_names.present?
|
70
|
+
|
71
|
+
opts[:name_context] = initial_context_names.map(&:key) * ","
|
72
|
+
end
|
73
|
+
|
74
|
+
def debug_slot
|
75
|
+
debug_slot? ? debug_slot_wrap { yield } : yield
|
76
|
+
end
|
77
|
+
|
78
|
+
def debug_slot?
|
79
|
+
params[:debug] == "slot"
|
80
|
+
end
|
81
|
+
|
82
|
+
def debug_slot_wrap
|
83
|
+
pre = "<!--\n\n#{' ' * depth}"
|
84
|
+
post = " SLOT: #{h card.name}\n\n-->"
|
85
|
+
[pre, "BEGIN", post, yield, pre, "END", post].join
|
86
|
+
end
|
87
|
+
|
88
|
+
def wrap_classes slot
|
89
|
+
list = slot ? ["card-slot"] : []
|
90
|
+
list += ["#{@current_view}-view", card.safe_set_keys]
|
91
|
+
list << "STRUCTURE-#{voo.structure.to_name.key}" if voo&.structure
|
92
|
+
classy list
|
93
|
+
end
|
94
|
+
|
95
|
+
def wrap_body
|
96
|
+
wrap_with(:div, class: body_css_classes) { yield }
|
97
|
+
end
|
98
|
+
|
99
|
+
def haml_wrap_body
|
100
|
+
wrap_body do
|
101
|
+
capture_haml { yield }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def body_css_classes
|
106
|
+
css_classes = ["d0-card-body"]
|
107
|
+
css_classes += ["d0-card-content", card.safe_set_keys] if @content_body
|
108
|
+
classy(*css_classes)
|
109
|
+
end
|
110
|
+
|
111
|
+
def wrap_main
|
112
|
+
return yield if no_main_wrap?
|
113
|
+
|
114
|
+
wrap_with :div, yield, id: "main"
|
115
|
+
end
|
116
|
+
|
117
|
+
def no_main_wrap?
|
118
|
+
Env.ajax? || params[:layout] == "none"
|
119
|
+
end
|
120
|
+
|
121
|
+
def wrap_with tag, content_or_args={}, html_args={}, &block
|
122
|
+
tag_args = block_given? ? content_or_args : html_args
|
123
|
+
content_tag(tag, tag_args) { content_within_wrap content_or_args, &block }
|
124
|
+
end
|
125
|
+
|
126
|
+
def wrap_each_with tag, content_or_args={}, args={}, &block
|
127
|
+
tag_args = block_given? ? content_or_args : args
|
128
|
+
content_items_within_wrap(content_or_args, args, &block).map do |item|
|
129
|
+
wrap_with(tag, tag_args) { item }
|
130
|
+
end.join "\n"
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def content_items_within_wrap content, args
|
136
|
+
content = block_given? ? yield(args) : content
|
137
|
+
content.compact
|
138
|
+
end
|
139
|
+
|
140
|
+
def content_within_wrap content
|
141
|
+
content = block_given? ? yield : content
|
142
|
+
output(content).to_s.html_safe
|
143
|
+
end
|
144
|
+
|
145
|
+
def html_escape_except_quotes string
|
146
|
+
# to be used inside single quotes (makes for readable json attributes)
|
147
|
+
string.to_s.gsub(/&/, "&")
|
148
|
+
.gsub(/\'/, "'")
|
149
|
+
.gsub(/>/, ">")
|
150
|
+
.gsub(/</, "<")
|
151
|
+
end
|
152
|
+
|
153
|
+
wrapper :div, :div
|
154
|
+
wrapper :em, :em
|
155
|
+
|
156
|
+
wrapper :none do
|
157
|
+
interior
|
158
|
+
end
|
159
|
+
end
|
data/set/all/js.rb
ADDED
data/set/all/json.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
format :json do
|
2
|
+
# because card.item_cards returns "[[#{self}]]"
|
3
|
+
def item_cards
|
4
|
+
nested_cards
|
5
|
+
end
|
6
|
+
|
7
|
+
def default_nest_view
|
8
|
+
:atom
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_item_view
|
12
|
+
params[:item] || :name
|
13
|
+
end
|
14
|
+
|
15
|
+
def max_depth
|
16
|
+
params[:max_depth].present? ? params[:max_depth].to_i : 1
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO: support layouts in json
|
20
|
+
# eg layout=stamp gives you the metadata currently in "page" view
|
21
|
+
# and layout=none gives you ONLY the requested view (default atom)
|
22
|
+
def show view, args
|
23
|
+
view ||= :molecule
|
24
|
+
string_with_page_details do
|
25
|
+
render! view, args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def string_with_page_details
|
30
|
+
raw = yield
|
31
|
+
return raw if raw.is_a? String
|
32
|
+
|
33
|
+
stringify page_details(raw)
|
34
|
+
end
|
35
|
+
|
36
|
+
def stringify raw
|
37
|
+
method = params[:compress] ? :generate : :pretty_generate
|
38
|
+
JSON.send method, raw
|
39
|
+
end
|
40
|
+
|
41
|
+
def page_details obj
|
42
|
+
return obj unless obj.is_a? Hash
|
43
|
+
|
44
|
+
obj.merge url: request_url, timestamp: Time.now.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
view :status, unknown: true, perms: :none do
|
48
|
+
{ key: card.key,
|
49
|
+
url_key: card.name.url_key,
|
50
|
+
status: card.state }.tap do |h|
|
51
|
+
|
52
|
+
h[:id] = card.id if h[:status] == :real
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def request_url
|
57
|
+
controller.request&.original_url || path
|
58
|
+
end
|
59
|
+
|
60
|
+
view :core, unknown: true do
|
61
|
+
card.known? ? render_content : nil
|
62
|
+
end
|
63
|
+
|
64
|
+
view :content do
|
65
|
+
card.content
|
66
|
+
end
|
67
|
+
|
68
|
+
view :nucleus do
|
69
|
+
nucleus
|
70
|
+
end
|
71
|
+
|
72
|
+
# TODO: add simple values for fields
|
73
|
+
view :atom, unknown: true do
|
74
|
+
atom
|
75
|
+
end
|
76
|
+
|
77
|
+
view :molecule do
|
78
|
+
molecule
|
79
|
+
end
|
80
|
+
|
81
|
+
view :page, cache: :never do
|
82
|
+
page_details card: render_atom
|
83
|
+
end
|
84
|
+
|
85
|
+
# NOCACHE because sometimes item_cards is dynamic.
|
86
|
+
# could be safely cached for non-dynamic lists
|
87
|
+
view :items, cache: :never do
|
88
|
+
listing item_cards, view: :atom
|
89
|
+
end
|
90
|
+
|
91
|
+
view :links do
|
92
|
+
card.link_chunks.map do |chunk|
|
93
|
+
if chunk.referee_name
|
94
|
+
path mark: chunk.referee_name, format: :json
|
95
|
+
else
|
96
|
+
link_to_resource chunk.link_target
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
view :ancestors do
|
102
|
+
card.name.ancestors.map do |name|
|
103
|
+
nest name, view: :nucleus
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# minimum needed to re-fetch card
|
108
|
+
view :cast do
|
109
|
+
card.cast
|
110
|
+
end
|
111
|
+
|
112
|
+
## DEPRECATED
|
113
|
+
view :marks do
|
114
|
+
{
|
115
|
+
id: card.id,
|
116
|
+
name: card.name,
|
117
|
+
key: card.key,
|
118
|
+
url: path
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
view :essentials do
|
123
|
+
if voo.show? :marks
|
124
|
+
render_marks.merge(essentials)
|
125
|
+
else
|
126
|
+
essentials
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def essentials
|
131
|
+
return {} if card.structure
|
132
|
+
{ content: card.db_content }
|
133
|
+
end
|
134
|
+
|
135
|
+
# NOTE: moving these to methods prevents potential caching problems, because other
|
136
|
+
# views manipulate their hashes.
|
137
|
+
#
|
138
|
+
def nucleus
|
139
|
+
{ id: card.id,
|
140
|
+
name: card.name,
|
141
|
+
type: card.type_name,
|
142
|
+
url: path(format: :json) }.tap do |h|
|
143
|
+
|
144
|
+
h[:codename] = card.codename if card.codename
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def atom
|
149
|
+
nucleus.tap do |h|
|
150
|
+
h[:content] = render_content if card.known? && !card.structure
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def molecule
|
155
|
+
atom.merge items: _render_items,
|
156
|
+
links: _render_links,
|
157
|
+
ancestors: _render_ancestors,
|
158
|
+
html_url: path,
|
159
|
+
type: nest(card.type_card, view: :nucleus)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# TODO: perhaps this should be in a general "data" module.
|
164
|
+
def cast
|
165
|
+
real? ? { id: id } : { name: name, type_id: type_id, content: db_content }
|
166
|
+
end
|