card-mod-format 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/lib/card/format/css_format.rb +17 -0
  3. data/lib/card/format/csv_format.rb +19 -0
  4. data/lib/card/format/data_format.rb +6 -0
  5. data/lib/card/format/file_format.rb +8 -0
  6. data/lib/card/format/html_format.rb +45 -0
  7. data/lib/card/format/js_format.rb +17 -0
  8. data/lib/card/format/json_format.rb +24 -0
  9. data/lib/card/format/rss_format.rb +9 -0
  10. data/lib/card/format/text_format.rb +16 -0
  11. data/lib/card/format/xml_format.rb +13 -0
  12. data/lib/card/path.rb +127 -0
  13. data/set/all/active_card.rb +6 -0
  14. data/set/all/base.rb +137 -0
  15. data/set/all/css.rb +37 -0
  16. data/set/all/csv.rb +93 -0
  17. data/set/all/error.rb +79 -0
  18. data/set/all/export.rb +68 -0
  19. data/set/all/file.rb +9 -0
  20. data/set/all/frame.rb +53 -0
  21. data/set/all/haml.rb +75 -0
  22. data/set/all/head.rb +148 -0
  23. data/set/all/header.rb +62 -0
  24. data/set/all/header/header_wrap.haml +4 -0
  25. data/set/all/html_content.rb +168 -0
  26. data/set/all/html_content/labeled.haml +4 -0
  27. data/set/all/html_error.rb +193 -0
  28. data/set/all/html_error/debug_server_error.haml +1015 -0
  29. data/set/all/html_error/not_found.haml +7 -0
  30. data/set/all/html_error/server_error.haml +5 -0
  31. data/set/all/html_show.rb +53 -0
  32. data/set/all/html_title.rb +47 -0
  33. data/set/all/html_wrapper.rb +159 -0
  34. data/set/all/js.rb +10 -0
  35. data/set/all/json.rb +166 -0
  36. data/set/all/links.rb +149 -0
  37. data/set/all/menu.rb +129 -0
  38. data/set/all/meta_tags.haml +4 -0
  39. data/set/all/path.rb +78 -0
  40. data/set/all/rich_html.rb +4 -0
  41. data/set/all/rss.rb +76 -0
  42. data/set/all/text.rb +7 -0
  43. data/set/self/home.rb +9 -0
  44. data/set/type/html.rb +27 -0
  45. data/set/type/json.rb +41 -0
  46. data/set/type/number.rb +22 -0
  47. data/set/type/phrase.rb +5 -0
  48. data/set/type/plain_text.rb +9 -0
  49. data/set/type/toggle.rb +38 -0
  50. data/set/type/uri.rb +15 -0
  51. metadata +123 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ef6d2c7a456c6e35591c10a980bc93de5b970d87d88bc6af9518acc0f314a6cc
4
+ data.tar.gz: d1f9e4f0ce72e65f79d8bf35391e95954317647628cbb342eb7617304fe9966c
5
+ SHA512:
6
+ metadata.gz: 53c0aef92bdd7fded5ff0a237d6d95aa1460a3612a9ec56a43e232be697ce627fffc69542ccdd3f2554d1f16df01f58459a85f575dc791981a906267b5d72c96
7
+ data.tar.gz: 74a7614d7a49a49e46fedc2f2064f523de67f98a88a9f06740dbe8f024edfa9a3dc3658a5e4cc4a7c0c137a8eebc783e3d9e4d6987aba658526d68d2d032992e
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class CssFormat < Format
6
+ register :css
7
+
8
+ def mime_type
9
+ "text/css"
10
+ end
11
+
12
+ def self.view_caching?
13
+ false
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class CsvFormat < TextFormat
6
+ register :csv
7
+
8
+ def mime_type
9
+ "text/comma-separated-values"
10
+ end
11
+
12
+ def self.view_caching?
13
+ # TODO: make view caching handle non-strings
14
+ # (specifically stub_render)
15
+ false
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ class Card
2
+ class Format
3
+ class DataFormat < Format
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class FileFormat < Format
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ # # require "card/content/diff"
4
+
5
+ class Card
6
+ class Format
7
+ # Main Format class for formatting card views in HTML
8
+ class HtmlFormat < Format
9
+ register :html
10
+
11
+ attr_accessor :options_need_save, :start_time, :skip_autosave
12
+
13
+ def main?
14
+ !@main.nil?
15
+ end
16
+
17
+ # is the current card the requested card?
18
+ def focal?
19
+ @focal ||= show_layout? ? main? : depth.zero?
20
+ end
21
+
22
+ def default_nest_view
23
+ # FIXME: not sure this makes sense as a rule...
24
+ card.rule(:default_html_view) || :titled
25
+ end
26
+
27
+ def default_item_view
28
+ :bar
29
+ end
30
+
31
+ def escape_literal literal
32
+ "<span>#{literal}</span>"
33
+ end
34
+
35
+ def mime_type
36
+ "text/html"
37
+ end
38
+
39
+ def final_render_call method
40
+ rendered = super
41
+ rendered.is_a?(Array) ? output(rendered) : rendered
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class JsFormat < Format
6
+ register :js
7
+
8
+ def self.view_caching?
9
+ false
10
+ end
11
+
12
+ def mime_type
13
+ "text/javascript"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class JsonFormat < DataFormat
6
+ register :json
7
+
8
+ def mime_type
9
+ "text/json"
10
+ end
11
+
12
+ def expand_stubs content
13
+ case content
14
+ when Hash
15
+ content.each { |k, v| content[k] = expand_stubs v }
16
+ when Array
17
+ content.map { |item| expand_stubs item }
18
+ else
19
+ super
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class RssFormat < HtmlFormat
6
+ register :rss
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class TextFormat < Format
6
+ register :text
7
+ register :txt
8
+ aliases["txt"] = "text"
9
+
10
+ def self.view_caching?
11
+ # probably overkill. problem was with email text message
12
+ false
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Card
4
+ class Format
5
+ class XmlFormat < DataFormat
6
+ register :xml
7
+
8
+ def mime_type
9
+ "text/xml"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,127 @@
1
+ class Card
2
+ # Generate standard card paths.
3
+ class Path
4
+ cattr_accessor :cast_params
5
+ self.cast_params = { slot: { hide: :array, show: :array, wrap: :array } }.freeze
6
+
7
+ def initialize card, opts
8
+ @card = card
9
+ @opts = opts
10
+ end
11
+
12
+ def render
13
+ new_cardtype || standard
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :opts
19
+
20
+ def action
21
+ @action ||= opts.delete(:action)&.to_sym
22
+ end
23
+
24
+ def new_cardtype
25
+ return unless new_cardtype?
26
+
27
+ "#{action}/#{mark}#{query}"
28
+ end
29
+
30
+ def new_cardtype?
31
+ return false unless action.in? %i[new type]
32
+
33
+ # "new" and "type" are not really an action and are only
34
+ # a valid value here for this path
35
+ opts[:mark].present?
36
+ end
37
+
38
+ def standard
39
+ base + extension + query
40
+ end
41
+
42
+ def base
43
+ explicit_action? ? action_base : mark
44
+ end
45
+
46
+ def action_base
47
+ mark.present? ? "#{action}/#{mark}" : "card/#{action}"
48
+ # the card/ prefix prevents interpreting action as cardname
49
+ end
50
+
51
+ def explicit_action?
52
+ action.in? %i[create update delete]
53
+ end
54
+
55
+ def mark
56
+ @mark ||= (markless? ? "" : interpret_mark)
57
+ end
58
+
59
+ def interpret_mark
60
+ name = handle_unknown do
61
+ opts[:mark] ? Card::Name[opts.delete(:mark)] : @card.name
62
+ end
63
+ name.url_key
64
+ end
65
+
66
+ def markless?
67
+ action == :create || no_mark?
68
+ end
69
+
70
+ def no_mark?
71
+ @no_mark ||= opts.delete :no_mark
72
+ end
73
+
74
+ def extension
75
+ extension = opts.delete :format
76
+ extension ? ".#{extension}" : ""
77
+ end
78
+
79
+ def query
80
+ query_opts = cast_path_hash opts
81
+ query_opts.empty? ? "" : "?#{query_opts.to_param}"
82
+ end
83
+
84
+ # normalizes certain path opts to specified data types
85
+ def cast_path_hash hash, cast_hash=nil
86
+ return hash unless hash.is_a? Hash
87
+ cast_each_path_hash hash, (cast_hash || self.class.cast_params)
88
+ hash
89
+ end
90
+
91
+ def cast_each_path_hash hash, cast_hash
92
+ hash.each do |key, value|
93
+ next unless (cast_to = cast_hash[key])
94
+ hash[key] = cast_path_value value, cast_to
95
+ end
96
+ end
97
+
98
+ def cast_path_value value, cast_to
99
+ if cast_to.is_a? Hash
100
+ cast_path_hash value, cast_to
101
+ else
102
+ send "cast_path_value_as_#{cast_to}", value
103
+ end
104
+ end
105
+
106
+ def cast_path_value_as_array value
107
+ Array.wrap value
108
+ end
109
+
110
+ def handle_unknown
111
+ yield.tap do |name|
112
+ return name if name_specified? || name_standardish?(name) || Card.known?(name)
113
+ opts[:card] ||= {}
114
+ opts[:card][:name] = name
115
+ end
116
+ end
117
+
118
+ def name_specified?
119
+ opts.dig :card, :name
120
+ end
121
+
122
+ # no name info will be lost by using url_key
123
+ def name_standardish? name
124
+ name.s == Card::Name.url_key_to_standard(name.url_key)
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,6 @@
1
+
2
+ # FIXME: -this needs a better home!
3
+ def format opts={}
4
+ opts = { format: opts.to_sym } if [Symbol, String].member? opts.class
5
+ Card::Format.new self, opts
6
+ end
@@ -0,0 +1,137 @@
1
+ format do
2
+ def show view, args
3
+ view ||= :core
4
+ render! view, args.merge(main_nest_options)
5
+ end
6
+
7
+ # NAME VIEWS
8
+
9
+ view :name, compact: true, perms: :none do
10
+ name_variant safe_name
11
+ end
12
+
13
+ def safe_name
14
+ card&.name
15
+ end
16
+
17
+ def name_variant name
18
+ voo.variant ? name.to_name.vary(voo.variant) : name
19
+ end
20
+
21
+ view(:key, compact: true, perms: :none) { card.key }
22
+ view(:linkname, compact: true, perms: :none) { card.name.url_key }
23
+ view(:url, compact: true, perms: :none) { card_url _render_linkname }
24
+
25
+ view :url_link, compact: true, perms: :none do
26
+ link_to_resource card_url(_render_linkname)
27
+ end
28
+
29
+ view :link, compact: true, perms: :none do
30
+ link_view
31
+ end
32
+
33
+ view :nav_link, compact: true, perms: :none do
34
+ link_view class: "nav-link"
35
+ end
36
+
37
+ def link_view opts={}
38
+ opts[:known] = card.known?
39
+ specify_type_in_link! opts
40
+ link_to_card card.name, _render_title, opts
41
+ end
42
+
43
+ def specify_type_in_link! opts
44
+ return if opts[:known] || !voo.type
45
+ opts[:path] = { card: { type: voo.type } }
46
+ end
47
+
48
+ view(:codename, compact: true) { card.codename.to_s }
49
+ view(:id, compact: true) { card.id }
50
+ view(:type, compact: true) { card.type_name }
51
+
52
+ # DATE VIEWS
53
+
54
+ view(:created_at, compact: true) { date_view card.created_at }
55
+ view(:updated_at, compact: true) { date_view card.updated_at }
56
+ view(:acted_at, compact: true) { date_view card.acted_at }
57
+
58
+ def date_view date
59
+ if voo.variant
60
+ date.strftime voo.variant
61
+ else
62
+ time_ago_in_words date
63
+ end
64
+ end
65
+
66
+ # CONTENT VIEWS
67
+
68
+ view :raw do
69
+ structure_card&.content || _render_blank
70
+ end
71
+
72
+ def structure_card
73
+ return nil if voo.structure == true
74
+ voo.structure ? Card[voo.structure] : card
75
+ end
76
+
77
+ view :core, compact: true do
78
+ process_content _render_raw
79
+ end
80
+
81
+ view :content do
82
+ _render_core
83
+ end
84
+
85
+ view :open_content do
86
+ _render_core
87
+ end
88
+
89
+ view :one_line_content, compact: true do
90
+ with_nest_mode :compact do
91
+ Card::Content.smart_truncate _render_core
92
+ end
93
+ end
94
+
95
+ view :labeled_content, unknown: :mini_unknown do
96
+ render_core
97
+ end
98
+
99
+ view :titled_content, unknown: :blank do
100
+ render_core
101
+ end
102
+
103
+ view :blank, compact: true, perms: :none do
104
+ ""
105
+ end
106
+
107
+ # note: content and open_content may look like they should be aliased to
108
+ # core, but it's important that they render core explicitly so that core view
109
+ # overrides work. the titled and labeled views below, however, are not
110
+ # intended for frequent override, so this shortcut is fine.
111
+
112
+ # NAME + CONTENT VIEWS
113
+
114
+ view :titled do
115
+ "#{card.name}\n\n#{_render_core}"
116
+ end
117
+ view :open, :titled
118
+
119
+ view :labeled do
120
+ "#{card.name}: #{_render_labeled_content}"
121
+ end
122
+ view :closed, :labeled
123
+
124
+ # SPECIAL VIEWS
125
+
126
+ view :array, cache: :never do
127
+ card.item_cards(limit: 0).map do |item_card|
128
+ subformat(item_card)._render_core
129
+ end.inspect
130
+ end
131
+
132
+ # DEPRECATED
133
+ view :naked do
134
+ Rails.logger.info "DEPRECATED: naked view (used with #{card.name} card)"
135
+ render_core
136
+ end
137
+ end