card 1.93.3 → 1.93.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/db/migrate/20170908114452_increase_text_size_for_delayed_jobs.rb +9 -0
  4. data/db/migrate_core_cards/data/cards/*header +2 -2
  5. data/lib/card/format/nest.rb +12 -5
  6. data/lib/card/format/nest/fetch.rb +1 -2
  7. data/lib/card/format/render.rb +2 -2
  8. data/lib/card/model/save_helper.rb +1 -1
  9. data/lib/card/set/format/haml_views.rb +7 -3
  10. data/lib/card/subcards.rb +27 -228
  11. data/lib/card/subcards/add.rb +121 -0
  12. data/lib/card/subcards/relate.rb +27 -0
  13. data/lib/card/subcards/remove.rb +42 -0
  14. data/lib/card/tasks/card/create.rake +35 -132
  15. data/lib/card/tasks/card/file_card_creator.rb +25 -0
  16. data/lib/card/tasks/card/file_card_creator/abstract_file_card.rb +44 -0
  17. data/lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb +49 -0
  18. data/lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb +30 -0
  19. data/lib/card/tasks/card/file_card_creator/abstract_file_card/source_file.rb +36 -0
  20. data/lib/card/tasks/card/file_card_creator/haml_card.rb +42 -0
  21. data/lib/card/tasks/card/file_card_creator/output_helper.rb +50 -0
  22. data/lib/card/tasks/card/file_card_creator/script_card.rb +33 -0
  23. data/lib/card/tasks/card/file_card_creator/style_card.rb +25 -0
  24. data/lib/generators/card/template/template_generator.rb +1 -1
  25. data/mod/account/set/self/account_links.rb +1 -1
  26. data/mod/basic_formats/set/all/all_csv.rb +63 -0
  27. data/mod/basic_formats/set/all/json.rb +4 -1
  28. data/mod/bootstrap/db/migrate_cards/20170719163733_update_bootswatch_themes_to_4_beta.rb +5 -2
  29. data/mod/carrierwave/set/abstract/attachment.rb +1 -2
  30. data/mod/core/set/abstract/haml_file.rb +20 -0
  31. data/mod/core/set/all/chunk.rb +125 -0
  32. data/mod/core/set/all/collection.rb +2 -351
  33. data/mod/core/set/all/content.rb +26 -7
  34. data/mod/core/set/all/extended.rb +45 -0
  35. data/mod/core/set/all/haml.rb +3 -7
  36. data/mod/core/set/all/item.rb +92 -0
  37. data/mod/core/set/all/name.rb +36 -0
  38. data/mod/core/set/all/subcards.rb +21 -12
  39. data/mod/core/set/all/tabs.rb +50 -0
  40. data/mod/core/set/all/trash.rb +4 -0
  41. data/mod/core/spec/set/all/chunk_spec.rb +45 -0
  42. data/mod/core/spec/set/all/collection_spec.rb +6 -6
  43. data/mod/history/set/all/action_view.rb +1 -1
  44. data/mod/machines/lib/javascript/decko.js.coffee +3 -0
  45. data/mod/pointer/set/abstract/02_pointer/edit.rb +0 -2
  46. data/mod/search/set/abstract/search.rb +1 -1
  47. data/mod/search/set/all/filter.rb +0 -2
  48. data/mod/search/template/all/filter/_filter_input.haml +1 -1
  49. data/mod/search/template/all/filter/filter_form.haml +1 -1
  50. data/mod/standard/set/all/rich_html/editing.rb +1 -1
  51. data/mod/standard/set/all/rich_html/form.rb +6 -7
  52. data/mod/standard/set/all/rich_html/menu.rb +2 -3
  53. data/mod/standard/set/all/rich_html/toolbar.rb +3 -4
  54. data/mod/standard/set/type/cardtype.rb +1 -1
  55. data/mod/standard/spec/set/all/rich_html/editing_spec.rb +15 -4
  56. data/mod/tinymce_editor/db/migrate_cards/{20171113233150_update_tinymce_config.rb → 20171113233151_update_tinymce_config.rb} +1 -0
  57. metadata +25 -161
  58. data/.rspec +0 -4
  59. data/card.gemspec +0 -87
  60. data/db/seed/test/fixtures/.gitkeep +0 -0
  61. data/mod/bootstrap/vendor/bootstrap/.babelrc.js +0 -16
  62. data/mod/bootstrap/vendor/bootstrap/.editorconfig +0 -17
  63. data/mod/bootstrap/vendor/bootstrap/.eslintignore +0 -3
  64. data/mod/bootstrap/vendor/bootstrap/.gitattributes +0 -16
  65. data/mod/bootstrap/vendor/bootstrap/.github/CONTRIBUTING.md +0 -252
  66. data/mod/bootstrap/vendor/bootstrap/.github/ISSUE_TEMPLATE.md +0 -22
  67. data/mod/bootstrap/vendor/bootstrap/.gitignore +0 -46
  68. data/mod/bootstrap/vendor/bootstrap/.hound.yml +0 -19
  69. data/mod/bootstrap/vendor/bootstrap/.houndignore +0 -4
  70. data/mod/bootstrap/vendor/bootstrap/.travis.yml +0 -32
  71. data/mod/bootstrap/vendor/bootstrap/build/.htmllintrc +0 -19
  72. data/mod/bootstrap/vendor/bootstrap/build/.stylelintrc +0 -248
  73. data/mod/bootstrap/vendor/bootstrap/docs/4.0/examples/.stylelintrc +0 -12
  74. data/mod/bootstrap/vendor/bootstrap/js/.eslintrc.json +0 -240
  75. data/mod/bootstrap/vendor/bootstrap/js/tests/.eslintrc.json +0 -46
  76. data/mod/bootstrap/vendor/bootswatch/.gitignore +0 -7
  77. data/mod/bootstrap/vendor/bootswatch/.npmignore +0 -12
  78. data/mod/bootstrap/vendor/bootswatch/.travis.yml +0 -21
  79. data/mod/bootstrap/vendor/bootswatch/docs/.nojekyll +0 -0
  80. data/mod/bootstrap/vendor/bootswatch/docs/2/.travis.yml +0 -15
  81. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.bower.json +0 -20
  82. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.gitignore +0 -37
  83. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.travis.yml +0 -3
  84. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/js/.jshintrc +0 -12
  85. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/jquery/.bower.json +0 -20
  86. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/jquery/.gitignore +0 -1
  87. data/mod/bootstrap/vendor/bootswatch/docs/2/swatchmaker/.gitignore +0 -1
  88. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap-sass-official/.bower.json +0 -45
  89. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/.bower.json +0 -44
  90. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/grunt/.jshintrc +0 -7
  91. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/js/.jscsrc +0 -42
  92. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/js/.jshintrc +0 -15
  93. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/less/.csscomb.json +0 -304
  94. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/less/.csslintrc +0 -19
  95. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/font-awesome/.bower.json +0 -14
  96. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/font-awesome/.gitignore +0 -32
  97. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/html5shiv/.bower.json +0 -25
  98. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/jquery/.bower.json +0 -38
  99. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/respond/.bower.json +0 -20
  100. data/mod/bootstrap/vendor/select2/.editorconfig +0 -6
  101. data/mod/bootstrap/vendor/select2/.github/CONTRIBUTING.md +0 -204
  102. data/mod/bootstrap/vendor/select2/.github/ISSUE_TEMPLATE.md +0 -46
  103. data/mod/bootstrap/vendor/select2/.github/PULL_REQUEST_TEMPLATE.md +0 -13
  104. data/mod/bootstrap/vendor/select2/.gitignore +0 -3
  105. data/mod/bootstrap/vendor/select2/.jshintignore +0 -4
  106. data/mod/bootstrap/vendor/select2/.jshintrc +0 -25
  107. data/mod/bootstrap/vendor/select2/.travis.yml +0 -22
  108. data/script/fetch_bootswatch_themes.rb +0 -38
  109. data/spec/config/initializers/core_extensions_spec.rb +0 -47
  110. data/spec/config/initializers/patches/active_job_spec.rb +0 -7
  111. data/spec/lib/card/action_spec.rb +0 -15
  112. data/spec/lib/card/auth_spec.rb +0 -58
  113. data/spec/lib/card/cache_spec.rb +0 -116
  114. data/spec/lib/card/chunk_spec.rb +0 -18
  115. data/spec/lib/card/codename_spec.rb +0 -66
  116. data/spec/lib/card/content_spec.rb +0 -428
  117. data/spec/lib/card/diff_spec.rb +0 -208
  118. data/spec/lib/card/format/nest_spec.rb +0 -13
  119. data/spec/lib/card/format/render_spec.rb +0 -26
  120. data/spec/lib/card/format_spec.rb +0 -117
  121. data/spec/lib/card/i18n_spec.rb +0 -24
  122. data/spec/lib/card/loader/Modfile +0 -2
  123. data/spec/lib/card/loader_spec.rb +0 -98
  124. data/spec/lib/card/migration/import_spec.rb +0 -80
  125. data/spec/lib/card/mod/loader/mod_dirs.rb +0 -8
  126. data/spec/lib/card/mod/loader/set_loader_spec.rb +0 -19
  127. data/spec/lib/card/mod/loader/set_pattern_loader_spec.rb +0 -19
  128. data/spec/lib/card/name/fields_and_traits_spec.rb +0 -18
  129. data/spec/lib/card/name_spec.rb +0 -70
  130. data/spec/lib/card/query/sorting_spec.rb +0 -68
  131. data/spec/lib/card/query_spec.rb +0 -574
  132. data/spec/lib/card/reference_spec.rb +0 -212
  133. data/spec/lib/card/set/event_spec.rb +0 -22
  134. data/spec/lib/card/set/trait_spec.rb +0 -80
  135. data/spec/lib/card/set_pattern_spec.rb +0 -59
  136. data/spec/lib/card/set_spec.rb +0 -89
  137. data/spec/lib/card/stage_director_spec.rb +0 -482
  138. data/spec/lib/card/subcards_spec.rb +0 -177
  139. data/spec/lib/card/success_spec.rb +0 -148
  140. data/spec/lib/card/view_cache_spec.rb +0 -27
  141. data/spec/mailers/mailer_spec.rb +0 -62
  142. data/spec/models/card/create_spec.rb +0 -119
  143. data/spec/models/card/trash_spec.rb +0 -189
  144. data/spec/models/card_spec.rb +0 -136
  145. data/spec/spec_helper.rb +0 -45
  146. data/spec/support/card_spec_helper.rb +0 -74
  147. data/spec/support/card_spec_loader.rb +0 -112
  148. data/spec/support/helper/card_helper.rb +0 -58
  149. data/spec/support/helper/event_helper.rb +0 -94
  150. data/spec/support/helper/render_helper.rb +0 -44
  151. data/spec/support/helper/save_helper.rb +0 -30
  152. data/spec/support/helper/set_helper.rb +0 -80
  153. data/spec/support/matchers/card_matchers.rb +0 -160
  154. data/spec/support/matchers/expectations.rb +0 -5
  155. data/spec/support/matchers/file_matchers.rb +0 -71
  156. data/spec/support/matchers/html_matchers.rb +0 -29
  157. data/spec/support/matchers/negated_matchers.rb +0 -2
  158. data/spec/support/simplecov_helper.rb +0 -70
  159. data/spec/support/test_mods/mod1/set/all/test_set.rb +0 -3
  160. data/spec/support/test_mods/mod2/set_pattern/test_pattern.rb +0 -0
@@ -0,0 +1,49 @@
1
+ class Card
2
+ class FileCardCreator
3
+ class AbstractFileCard
4
+ # Module that provides #create_migration_file method for classes that
5
+ # inherit from AbstractFileCard.
6
+ # It uses the decko generator to create the migration.
7
+ module MigrationFile
8
+ def create_migration_file
9
+ puts "creating migration file...".yellow
10
+ migration_out = `#{migrate_command}`
11
+ return if migration_out.include?("conflict")
12
+ migration_file_name = migration_out[/db.*/]
13
+ write_at migration_file_name, 5, indented_migration_content # 5 is line no.
14
+ end
15
+
16
+ private
17
+
18
+ def migrate_command
19
+ cmd = "bundle exec decko generate card:migration add_#{@codename}"
20
+ cmd += " --force" if @force
21
+ cmd
22
+ end
23
+
24
+ def indented_migration_content
25
+ migration_file_content.lines.map do |line|
26
+ " " * 4 + line
27
+ end.join
28
+ end
29
+
30
+ def migration_file_content
31
+ indent = " " * category.to_s.size
32
+ <<-RUBY.strip_heredoc
33
+ add_#{category} "#{remove_prefix @name}",
34
+ #{indent} type_id: #{type_id},
35
+ #{indent} to: "#{rule_card_name}"
36
+ RUBY
37
+ end
38
+
39
+ def remove_prefix name
40
+ name.sub(/^(?:#{category}):?_?\s*/, "")
41
+ end
42
+
43
+ def type_id
44
+ "Card::#{type_codename.to_s.camelcase}ID"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ class Card
2
+ class FileCardCreator
3
+ class AbstractFileCard
4
+ # Module that provides #create_ruby_file method for a classes that
5
+ # inherit from AbstractFileCard.
6
+ # The default location for the ruby file is set/self.
7
+ module RubyFile
8
+ def create_ruby_file
9
+ write_to_mod(ruby_file_dir, ruby_file_name) do |f|
10
+ f.puts ruby_file_content
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def ruby_file_dir
17
+ File.join "set", "self"
18
+ end
19
+
20
+ def ruby_file_name
21
+ @codename + ".rb"
22
+ end
23
+
24
+ def ruby_file_content
25
+ "include_set Abstract::CodeFile"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ class Card
2
+ class FileCardCreator
3
+ class AbstractFileCard
4
+ # Module that provides #create_source_file method for a classes that
5
+ # inherit from AbstractFileCard
6
+ module SourceFile
7
+ def create_source_file
8
+ write_to_mod source_file_dir, source_file_name do |f|
9
+ f.puts source_file_content
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def source_file_content
16
+ card = Card.fetch(@name)
17
+ if card
18
+ card.content
19
+ else
20
+ color_puts "warning:", :yellow,
21
+ "Card '#{@name}' doesn't exist. Creating empty source file ..."
22
+ ""
23
+ end
24
+ end
25
+
26
+ def source_file_name
27
+ "#{@codename}.#{source_file_ext}"
28
+ end
29
+
30
+ def source_file_ext
31
+ @type
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
1
+ require "html2haml"
2
+
3
+ class Card
4
+ class FileCardCreator
5
+ # Convert a card with html db content to a card with hard-coded haml.
6
+ # It generates three files:
7
+ # 1. a migration file that creates a card with codename
8
+ # 2. a haml file with the converted html
9
+ # 3. a ruby file (=code rule)that ties the haml file to the card
10
+ class HamlCard < AbstractFileCard
11
+ @supported_types = %i[haml]
12
+ @category = :haml
13
+
14
+ private
15
+
16
+ def type_codename
17
+ @type_codename ||= :html
18
+ end
19
+
20
+ def source_file_dir
21
+ File.join "template", "self"
22
+ end
23
+
24
+ def source_file_content
25
+ html = super()
26
+ Html2haml::HTML.new(html).render
27
+ end
28
+
29
+ def migration_file_content
30
+ <<-RUBY.strip_heredoc
31
+ ensure_card "#{@name}",
32
+ type_id: #{type_id},
33
+ codename: "#{@codename}"
34
+ RUBY
35
+ end
36
+
37
+ def ruby_file_content
38
+ "include_set Abstract::HamlFile"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ class Card
2
+ class FileCardCreator
3
+ # Helper methods to write to files and the console.
4
+ module OutputHelper
5
+ def write_to_mod rel_dir, filename
6
+ dir = File.join "mod", @mod, rel_dir
7
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
8
+
9
+ path = File.join dir, filename
10
+ log_file_action path do
11
+ File.open(path, "w") do |opened_file|
12
+ yield(opened_file)
13
+ end
14
+ end
15
+ end
16
+
17
+ def log_file_action path
18
+ status, color =
19
+ if File.exist?(path) && !@force
20
+ ["file exists (use 'force=true' to override)", :yellow]
21
+ else
22
+ status = File.exist?(path) ? "overridden" : "created"
23
+ yield
24
+ [status, :green]
25
+ end
26
+
27
+ color_puts status, color, path
28
+ end
29
+
30
+ # insert content into a file at a given line number
31
+ def write_at fname, at_line, sdat
32
+ open(fname, "r+") do |f|
33
+ (at_line - 1).times do # read up to the line you want to write after
34
+ f.readline
35
+ end
36
+ pos = f.pos # save your position in the file
37
+ rest = f.read # save the rest of the file
38
+ f.seek pos # go back to the old position
39
+ f.puts sdat # write new data & rest of file
40
+ f.puts rest
41
+ color_puts "created", :green, fname
42
+ end
43
+ end
44
+
45
+ def color_puts colored_text, color, text=""
46
+ puts "#{colored_text.send(color.to_s)} #{text}"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+ class Card
2
+ class FileCardCreator
3
+ # Move javascript or coffeescript from the card database to a file.
4
+ # It generates three files:
5
+ # 1. a migration file that ensures the card has a codename and adds it to the
6
+ # script rule card.
7
+ # 2. a script file with the source code
8
+ # 3. a ruby file (=code rule) that ties the script file to the card
9
+ class ScriptCard < AbstractFileCard
10
+ @supported_types = %i[js coffee]
11
+ @category = :script
12
+ @default_rule_name = "*all+*script"
13
+
14
+ private
15
+
16
+ def source_file_ext
17
+ @type == :coffee ? "js.coffee" : @type
18
+ end
19
+
20
+ def type_codename
21
+ @type_codename ||=
22
+ case @type
23
+ when :js then :java_script
24
+ when :coffee then :coffee_script
25
+ end
26
+ end
27
+
28
+ def source_file_dir
29
+ File.join "lib", "javascript"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ class Card
2
+ class FileCardCreator
3
+ # Move css or scss from the card database to a file.
4
+ # It generates three files:
5
+ # 1. a migration file that ensures the card has a codename and adds it to the
6
+ # style rule card.
7
+ # 2. a style file with the source code
8
+ # 3. a ruby file (=code rule) that ties the style file to the card
9
+ class StyleCard < AbstractFileCard
10
+ @supported_types = %i[css scss]
11
+ @category = :style
12
+ @default_rule_name = "*all+*style"
13
+
14
+ private
15
+
16
+ def type_codename
17
+ @type_codename ||= @type.to_sym
18
+ end
19
+
20
+ def source_file_dir
21
+ File.join "lib", "stylesheets"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -27,7 +27,7 @@ class Card
27
27
  if !Dir.exist? mod_path
28
28
  warn "invalid mod name: #{file_name}. Directory #{mod_path} doesn't exist."
29
29
  # Card.set_patterns not loaded at this point
30
- elsif !%w[self type type_plus_right ltype_rtype rstar star
30
+ elsif !%w[self type right type_plus_right ltype_rtype rstar star
31
31
  type all_plus all].include? set_pattern
32
32
  warn "invalid set pattern: #{set_pattern}"
33
33
  else
@@ -3,7 +3,7 @@ format :html do
3
3
  def item_links _args=nil
4
4
  %i[my_card invite sign_out sign_up sign_in].map do |link_view|
5
5
  render link_view
6
- end
6
+ end.compact
7
7
  end
8
8
 
9
9
  def self.link_options opts={}
@@ -9,6 +9,14 @@ format :csv do
9
9
  depth.zero? ? :csv_row : :name
10
10
  end
11
11
 
12
+ view :core do
13
+ if (item_view_options[:view] == :name_with_fields) && focal?
14
+ title_row("item name") + name_with_field_rows
15
+ else
16
+ super()
17
+ end
18
+ end
19
+
12
20
  view :csv_row do
13
21
  array = _render_raw.scan(/\{\{[^\}]*\}\}/).map do |inc|
14
22
  process_content(inc).strip
@@ -31,4 +39,59 @@ format :csv do
31
39
  row << nest(field_name)
32
40
  end
33
41
  end
42
+
43
+ def name_with_field_rows
44
+ return [] unless row_card_names.present?
45
+
46
+ row_card_names.map do |item_name|
47
+ CSV.generate_line row_from_field_names(item_name, columns)
48
+ end.join
49
+ end
50
+
51
+ def row_card_names
52
+ @row_cards ||= card.item_names
53
+ end
54
+
55
+ def columns
56
+ columns = []
57
+ csv_structure_card.format.each_nested_field do |chunk|
58
+ columns << chunk.referee_name.tag
59
+ end
60
+ columns
61
+ end
62
+
63
+ def csv_structure_card
64
+ card.rule_card(:csv_structure) || Card.fetch(row_card_names.first)
65
+ end
66
+
67
+ def row_from_field_names parent_name, field_names, view=:core
68
+ field_names.each_with_object([parent_name]) do |field, row|
69
+ row << nest([parent_name, field], view: view)
70
+ end
71
+ end
72
+
73
+ def title_row extra_titles=nil
74
+ titles = column_titles extra_titles
75
+ return "" unless titles.present?
76
+ CSV.generate_line titles.map(&:upcase)
77
+ end
78
+
79
+ def column_titles extra_titles=nil
80
+ res = Array extra_titles
81
+ card1 = Card.fetch card.item_names(limit: 1).first
82
+ card1.each_nested_chunk do |chunk|
83
+ res << column_title(chunk.options)
84
+ end
85
+ res.compact
86
+ end
87
+
88
+ def column_title opts
89
+ if opts[:title]
90
+ opts[:title]
91
+ elsif %w[name link].member? opts[:view]
92
+ opts[:view]
93
+ else
94
+ opts[:nest_name].to_name.tag
95
+ end
96
+ end
34
97
  end
@@ -39,7 +39,10 @@ format :json do
39
39
  end
40
40
 
41
41
  def name_search query_attribute: :complete, limit: AUTOCOMPLETE_LIMIT
42
- card.search limit: limit, sort: "name", return: "name", query_attribute => params[:term]
42
+ card.search limit: limit,
43
+ sort: "name",
44
+ return: "name",
45
+ query_attribute => params[:term]
43
46
  end
44
47
 
45
48
  view :status, tags: :unknown_ok, perms: :none, cache: :never do
@@ -36,8 +36,11 @@ class UpdateBootswatchThemesTo4Beta < Card::Migration::Core
36
36
  end
37
37
 
38
38
  def update_bootstrap_default
39
- ensure_scss "default bootstrap skin+bootswatch theme",
40
- content: "{{bootstrap: functions}}{{bootstrap: variables}}{{bootstrap: core}}"
39
+ ensure_card "bootstrap default skin+bootswatch theme",
40
+ type_id: Card::ScssID,
41
+ content: "{{bootstrap: functions}}" \
42
+ "{{bootstrap: variables}}" \
43
+ "{{bootstrap: core}}"
41
44
  end
42
45
 
43
46
  def add_icon_cards
@@ -54,8 +54,7 @@ def original_filename
54
54
  end
55
55
 
56
56
  def unfilled?
57
- !attachment.present? && !save_preliminary_upload? && !subcards.present? &&
58
- !content.present?
57
+ !attachment.present? && !save_preliminary_upload? && !subcards? && blank_content?
59
58
  end
60
59
 
61
60
  def attachment_changed?
@@ -0,0 +1,20 @@
1
+
2
+ def self.included host_class
3
+ host_class.mattr_accessor :template_path
4
+ host_class.extend Card::Set::Format::HamlViews
5
+ host_class.template_path = host_class.haml_template_path
6
+ end
7
+
8
+ def content
9
+ File.read template_path
10
+ end
11
+
12
+ format :html do
13
+ def haml_locals
14
+ {}
15
+ end
16
+
17
+ view :core do
18
+ haml card.content, haml_locals
19
+ end
20
+ end
@@ -0,0 +1,125 @@
1
+
2
+ def chunks content, type
3
+ content ||= self.content
4
+ type ||= Card::Content::Chunk
5
+ Card::Content.new(content, self).find_chunks type
6
+ end
7
+
8
+ def each_chunk content, type
9
+ chunks(content, type).each do |chunk|
10
+ next unless chunk.referee_name # filter commented nests
11
+ yield chunk
12
+ end
13
+ end
14
+
15
+ def each_reference_chunk content=nil
16
+ each_chunk content, Card::Content::Chunk::Reference do |chunk|
17
+ yield chunk
18
+ end
19
+ end
20
+
21
+ def each_nested_chunk content=nil
22
+ each_chunk content, Card::Content::Chunk::Nest do |chunk|
23
+ yield chunk
24
+ end
25
+ end
26
+
27
+ def each_item_name_with_options content=nil
28
+ each_reference_chunk content do |chunk|
29
+ options = chunk.respond_to?(:options) ? chunk.options : {}
30
+ yield chunk.referee_name, options
31
+ end
32
+ end
33
+
34
+ format do
35
+ def nested_fields content=nil
36
+ result = []
37
+ each_nested_card(content) do |chunk|
38
+ result << [chunk.referee_name, chunk.options]
39
+ end
40
+ result
41
+ end
42
+
43
+ def nested_cards_for_edit fields_only=false
44
+ return normalized_edit_fields if edit_fields.present?
45
+ result = []
46
+ each_nested_card nil, fields_only do |chunk|
47
+ result << [chunk.options[:nest_name], chunk.options]
48
+ end
49
+ result
50
+ end
51
+
52
+ def edit_fields
53
+ voo.edit_structure || []
54
+ end
55
+
56
+ def normalized_edit_fields
57
+ edit_fields.map do |cardish, options|
58
+ field_mark = normalized_edit_field_mark cardish, options
59
+ options = normalized_edit_field_options options, Card::Name[field_mark]
60
+ [field_mark, options]
61
+ end
62
+ end
63
+
64
+ def normalized_edit_field_options options, cardname
65
+ options ||= cardname
66
+ options.is_a?(String) ? { title: options } : options
67
+ end
68
+
69
+ def normalized_edit_field_mark cardish, options
70
+ return cardish if cardish.is_a?(Card) ||
71
+ (options.is_a?(Hash) && options.delete(:absolute))
72
+ card.name.field cardish
73
+ end
74
+
75
+ def process_field chunk, processed, &_block
76
+ return unless process_unique_field? chunk, processed
77
+ yield chunk
78
+ end
79
+
80
+ def each_nested_field content=nil, &block
81
+ each_nested_card content, true, &block
82
+ end
83
+
84
+ def each_nested_card content=nil, fields_only=true, &block
85
+ processed = process_tally
86
+ each_nested_chunk content do |chunk|
87
+ next if fields_only && !field_chunk?(chunk)
88
+ process_nested_chunk chunk, processed, &block
89
+ end
90
+ end
91
+
92
+ def each_nested_chunk content, &block
93
+ content ||= _render_raw
94
+ card.each_nested_chunk content, &block
95
+ end
96
+
97
+ def process_tally
98
+ ::Set.new [card.key]
99
+ end
100
+
101
+ def field_chunk? chunk
102
+ chunk.referee_name.to_name.field_of? card.name
103
+ end
104
+
105
+ def process_nested_chunk chunk, processed, &block
106
+ virtual = chunk.referee_card && chunk.referee_card.virtual?
107
+ # TODO: handle structures that are non-virtual
108
+ method = virtual ? :process_virtual_field : :process_field
109
+ send method, chunk, processed, &block
110
+ end
111
+
112
+ def process_virtual_field chunk, processed, &block
113
+ return unless process_unique_field? chunk, processed
114
+ subformat(chunk.referee_card).each_nested_field do |sub_chunk|
115
+ process_field sub_chunk, processed, &block
116
+ end
117
+ end
118
+
119
+ def process_unique_field? chunk, processed
120
+ key = chunk.referee_name.key
121
+ return false if processed.include? key
122
+ processed << key
123
+ true
124
+ end
125
+ end