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,121 @@
1
+ class Card
2
+ class Subcards
3
+ # Methods for adding subcards
4
+ module Add
5
+ # @example Add a subcard with name 'spoiler'
6
+ # add 'spoiler', type: 'Phrase', content: 'John Snow is a Targaryen'
7
+ # card_obj = Card.new name: 'spoiler', type: 'Phrase',
8
+ # content: 'John Snow is a Targaryen'
9
+ # add card_obj
10
+ # add name: 'spoiler', type: 'Phrase', content: 'John Snow is a Targaryen'
11
+ #
12
+ # @example Add a subcard that is added in the integration phase
13
+ # (and hence doesn't hold up the transaction for the main card)
14
+ # add 'spoiler', content: 'John Snow is a Targaryen',
15
+ # transact_in_stage: :integrate
16
+ # add card_obj, delayed: true
17
+
18
+ def << value
19
+ add value
20
+ end
21
+
22
+ def []= name, card_or_attr
23
+ case card_or_attr
24
+ when Hash
25
+ new_by_attributes name, card_or_attr
26
+ when Card
27
+ new_by_card card_or_attr
28
+ end
29
+ end
30
+
31
+ def add *args
32
+ case args.first
33
+ when Card then new_by_card(*args)
34
+ when Hash then add_hash args.first
35
+ else new_by_attributes(*args)
36
+ end
37
+ end
38
+
39
+ def add_hash hash
40
+ if (name = hash.delete :name)
41
+ new_by_attributes name, hash
42
+ else
43
+ multi_add hash
44
+ end
45
+ end
46
+
47
+ def add_child name, args
48
+ name = name.is_a?(Symbol) ? name.cardname : name.to_name
49
+ add name.prepend_joint, args
50
+ end
51
+ alias_method :add_field, :add_child
52
+
53
+ def new_by_card card, opts={}
54
+ card.supercard = @context_card
55
+ if !card.name.simple? && card.name.field_of?(@context_card.name)
56
+ card.superleft = @context_card
57
+ end
58
+ @keys << card.key
59
+ Card.write_to_soft_cache card
60
+ card.director = @context_card.director.subdirectors.add(card, opts)
61
+ card
62
+ end
63
+
64
+ def new_by_attributes name, attributes={}
65
+ attributes ||= {}
66
+ absolute_name = absolutize_subcard_name name
67
+ subcard_args = extract_subcard_args! attributes
68
+ t_i_s = attributes.delete(:transact_in_stage)
69
+ card = initialize_by_attributes absolute_name, attributes
70
+ subcard = new_by_card card, transact_in_stage: t_i_s
71
+ card.subcards.add subcard_args
72
+ subcard
73
+ end
74
+
75
+ def initialize_by_attributes name, attributes
76
+ Card.assign_or_initialize_by name, attributes, local_only: true
77
+ end
78
+
79
+ # TODO: this method already exists as card instance method in
80
+ # tracked_attributes.rb. Find a place for it where its accessible
81
+ # for both. There is one important difference. The keys are symbols
82
+ # here instead of strings
83
+ def extract_subcard_args! args
84
+ subcards = args.delete(:subcards) || {}
85
+ if (subfields = args.delete(:subfields))
86
+ subfields.each_pair do |key, value|
87
+ subcards[normalize_subfield_key(key)] = value
88
+ end
89
+ end
90
+ args.keys.each do |key|
91
+ subcards[key] = args.delete(key) if key =~ /^\+/
92
+ end
93
+ subcards
94
+ end
95
+
96
+ private
97
+
98
+ # ensure a leading '+'
99
+ def normalize_subfield_key key
100
+ if key.is_a?(Symbol) && Card::Codename.exist?(key)
101
+ key = Card::Codename.name(key)
102
+ end
103
+ key.to_name.prepend_joint
104
+ end
105
+
106
+ # Handles hash with several subcards
107
+ def multi_add args
108
+ args.each_pair do |key, val|
109
+ case val
110
+ when String then new_by_attributes key, content: val
111
+ when Card
112
+ val.name = absolutize_subcard_name key
113
+ new_by_card val
114
+ when nil then next
115
+ else new_by_attributes key, val
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,27 @@
1
+ class Card
2
+ class Subcards
3
+ # Methods for handling related subcards
4
+ module Relate
5
+ def field_name_to_key name
6
+ if @context_card.name.starts_with_joint?
7
+ relative_child(name).key
8
+ else
9
+ child(name).key
10
+ end
11
+ end
12
+
13
+ def child name
14
+ absolute_name = @context_card.name.field_name name
15
+ if @keys.include? absolute_name.key
16
+ absolute_name
17
+ else
18
+ relative_child name
19
+ end
20
+ end
21
+
22
+ def relative_child name
23
+ @context_card.name.relative_field_name name
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ class Card
2
+ class Subcards
3
+ # Methods for removing/clearing subcards
4
+ module Remove
5
+ def remove_child cardish
6
+ child = cardish.is_a?(Card) ? cardish : child(cardish)
7
+ remove child
8
+ end
9
+ alias_method :remove_field, :remove_child
10
+
11
+ def remove name_or_card
12
+ key = subcard_key name_or_card
13
+ return unless @keys.include? key
14
+ @keys.delete key
15
+ clear_key key
16
+ end
17
+
18
+ def clear
19
+ @keys.each { |key| clear_key key }
20
+ @keys = ::Set.new
21
+ end
22
+
23
+ def clear_key key
24
+ if (subcard = fetch_subcard key)
25
+ ActManager.deep_delete subcard.director
26
+ subcard.current_action&.delete
27
+ end
28
+ Card.cache.soft.delete key
29
+ subcard
30
+ end
31
+
32
+ def deep_clear cleared=::Set.new
33
+ each_card do |card|
34
+ next if cleared.include? card.id
35
+ cleared << card.id
36
+ card.subcards.deep_clear cleared
37
+ end
38
+ clear
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,31 +2,38 @@ require "colorize"
2
2
 
3
3
  namespace :card do
4
4
  namespace :create do
5
- DEFAULT_RULE = { style: "*all+*style",
6
- script: "*all+*script" }.freeze
7
-
8
- # 1. Creates a js/coffee/css/scss file with the appropriate path in
5
+ # 1. Creates a js/coffee/css/scss/haml source file with the appropriate path in
9
6
  # the given mod.
10
7
  # If a card with the given name exists it copies the content to that
11
8
  # file.
12
- # 2. Creates a self set file that loads the code file as content
9
+ # 2. Creates a self set file that loads the source file as content
13
10
  # 3. Creates a card migration that adds the code card to the script/style
14
- # rule defined by DEFAULT_RULE. Override the rule_card_name
15
- # method to change it.
16
- # @parem mod [String] the name of the mod where the files are created
11
+ # rule defined by ScriptCard/StyleCard.default_rule_name.
12
+ # Override the set_default_rule_names method to change it.
13
+ # In the haml case it creates a html card with codename.
14
+ # @param mod [String] the name of the mod where the files are created
17
15
  # @param name [String] the card name
18
- # A "script: " or "style: " prefix is added if missing.
19
- # Whitespaces are translated to underscores for the codename.
20
- # @param type supported options are js, coffee, css, scss
21
- desc "create folders and files for scripts or styles"
16
+ # @param type [String] supported options are js, coffee, css, scss, haml
17
+ # @param codename [String] optional defaults to key of the name
18
+ # @param force ["true", "false"] if true override existing files
19
+ # @example
20
+ # rake card:create:codefile type=scss mod=standard name="script card"
21
+ # codename=not_the_key force=true
22
+ desc "create folders and files for scripts, styles or haml"
22
23
  task codefile: :environment do
23
- with_params(:mod, :name, :type) do |mod, name, category, type, type_codename|
24
- create_content_file mod, name, type
25
- create_rb_file mod, name
26
- create_migration_file name, category, type_codename
24
+ set_default_rule_names
25
+ with_params :mod, :name, :type,
26
+ codename: nil, force: false do |mod, name, type, codename, force|
27
+ Card::FileCardCreator.new(mod, name, type, codename, force == "true").create
27
28
  end
28
29
  end
29
30
 
31
+ # override to which rule cards script and styles cards are added
32
+ def set_default_rule_names
33
+ # Card::FileCardCreator::ScriptCard.default_rule_name =
34
+ # Card::FileCardCreator::StyleCard.default_rule_name =
35
+ end
36
+
30
37
  # shortcut for create:codefile type=scss
31
38
  desc "create folders and files for stylesheet"
32
39
  task style: :environment do
@@ -41,137 +48,33 @@ namespace :card do
41
48
  Rake::Task["card:create:codefile"].invoke
42
49
  end
43
50
 
44
- def create_content_file mod, name, type
45
- write_to_mod(mod, content_dir(type), content_filename(name, type)) do |f|
46
- content = (card = Card.fetch(name)) ? card.content : ""
47
- f.puts content
48
- end
49
- end
50
-
51
- def create_rb_file mod, name
52
- self_dir = File.join "set", "self"
53
- self_file = name + ".rb"
54
- write_to_mod(mod, self_dir, self_file) do |f|
55
- f.puts("include_set Abstract::CodeFile")
56
- end
57
- end
58
-
59
- def create_migration_file name, category, type_codename
60
- puts "creating migration file...".yellow
61
- migration_out = `bundle exec decko generate card:migration #{name}`
62
- migration_file = migration_out[/db.*/]
63
- content = migration_content name, category, type_codename
64
- write_at migration_file, 5, content # 5 is line no.
51
+ # shortcut for create:codefile type=haml
52
+ desc "create folders and files for haml"
53
+ task haml: :environment do
54
+ ENV["type"] ||= "haml"
55
+ Rake::Task["card:create:codefile"].invoke
65
56
  end
66
57
 
67
58
  def with_params *keys
68
- return unless parameters_present?(*keys)
59
+ optional_params = keys.last.is_a?(Hash) ? keys.pop : {}
60
+ return unless params_present?(*keys)
69
61
  values = keys.map { |k| ENV[k.to_s] }
70
- mod, name, type = values
71
- name = remove_prefix name
72
- typecode = type_codename(type)
73
- yield mod, name, category(typecode), type, typecode
74
- end
75
-
76
- def remove_prefix name
77
- name.sub(/^(?:script|style):?_?\s*/, "")
78
- end
79
-
80
- def category typecode
81
- case typecode
82
- when :java_script, :coffee_script then
83
- :script
84
- when :css, :scss then
85
- :style
62
+ optional_params.each_pair do |k, v|
63
+ values << (ENV[k.to_s] || v)
86
64
  end
65
+ yield(*values)
87
66
  end
88
67
 
89
- def parameters_present? *env_keys
68
+ def params_present? *env_keys
90
69
  missing = env_keys.select { |k| !ENV[k.to_s] }
91
- return true if missing.empty?
92
70
  missing.each do |key|
93
71
  color_puts "missing parameter:", :red, key
94
72
  end
95
- false
73
+ missing.empty?
96
74
  end
97
75
 
98
76
  def color_puts colored_text, color, text=""
99
77
  puts "#{colored_text.send(color.to_s)} #{text}"
100
78
  end
101
-
102
- def write_at fname, at_line, sdat
103
- open(fname, "r+") do |f|
104
- (at_line - 1).times do # read up to the line you want to write after
105
- f.readline
106
- end
107
- pos = f.pos # save your position in the file
108
- rest = f.read # save the rest of the file
109
- f.seek pos # go back to the old position
110
- f.puts sdat # write new data & rest of file
111
- f.puts rest
112
- color_puts "created", :green, fname
113
- end
114
- end
115
-
116
- def write_to_mod mod, relative_dir, filename
117
- mod_dir = File.join "mod", mod
118
- dir = File.join mod_dir, relative_dir
119
- path = File.join dir, filename
120
- Dir.mkdir(dir) unless Dir.exist?(dir)
121
- if File.exist?(path)
122
- color_puts "file exists", :yellow, path
123
- else
124
- File.open(path, "w") do |opened_file|
125
- yield(opened_file)
126
- color_puts "created", :green, path
127
- end
128
- end
129
- end
130
-
131
- def type_codename type
132
- case type
133
- when "js" then
134
- :java_script
135
- when "coffee" then
136
- :coffee_script
137
- when "css", "scss" then
138
- type.to_sym
139
- else
140
- color_puts "'#{type}' is not a valid type. "\
141
- "Please choose between js, coffee, css and scss.", :red
142
- exit
143
- end
144
- end
145
-
146
- def migration_content name, category, type_codename
147
- <<-RUBY
148
- add_#{category} "#{name}",
149
- type_id: #{type_id type_codename},
150
- to: "#{rule_card_name category}"
151
- RUBY
152
- end
153
-
154
- def content_dir type
155
- dir = case type
156
- when "js", "coffee" then
157
- "javascript"
158
- when "css", "scss" then
159
- "stylesheets"
160
- end
161
- File.join "lib", dir
162
- end
163
-
164
- def content_filename name, type
165
- file_ext = type == "coffee" ? ".js.coffee" : "." + type
166
- name + file_ext
167
- end
168
-
169
- def type_id type_codename
170
- "Card::#{type_codename.to_s.camelcase}ID"
171
- end
172
-
173
- def rule_card_name category
174
- DEFAULT_RULE[category]
175
- end
176
79
  end
177
80
  end
@@ -0,0 +1,25 @@
1
+ class Card
2
+ # A Factory class
3
+ # It choses the class to create the file card accoring to the given type.
4
+ class FileCardCreator
5
+ CARD_CLASSES = [StyleCard, ScriptCard, HamlCard].freeze
6
+
7
+ attr_reader :creator
8
+
9
+ def initialize mod, name, type, codename, force
10
+ card_class = FileCardCreator.card_class type
11
+ unless card_class
12
+ raise "'#{type}' is not a valid type. "\
13
+ "Please choose between js, coffee, css, scss and haml", :red
14
+ end
15
+
16
+ @creator = card_class.new mod, name, type, codename: codename, force: force
17
+ end
18
+ def self.card_class type
19
+
20
+ CARD_CLASSES.find { |cc| cc.valid_type? type }
21
+ end
22
+
23
+ delegate :create, to: :creator
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ class Card
2
+ class FileCardCreator
3
+ # A template class for generating cards that are linked to source files.
4
+ class AbstractFileCard
5
+ include OutputHelper
6
+ include SourceFile
7
+ include MigrationFile
8
+ include RubyFile
9
+
10
+ class << self
11
+ attr_reader :supported_types, :category
12
+ attr_accessor :default_rule_name
13
+
14
+ def valid_type? type
15
+ supported_types.include? type.to_sym
16
+ end
17
+ end
18
+
19
+ def initialize mod, name, type, codename: nil, force: false
20
+ @mod = mod
21
+ @type = type.to_sym
22
+ @name = name
23
+ @force = force
24
+ @codename = codename || name.to_name.key
25
+ end
26
+
27
+ def create
28
+ create_source_file
29
+ create_ruby_file
30
+ create_migration_file
31
+ end
32
+
33
+ def category
34
+ self.class.category
35
+ end
36
+
37
+ private
38
+
39
+ def rule_card_name
40
+ self.class.default_rule_name
41
+ end
42
+ end
43
+ end
44
+ end