card-mod-assets 0.14.2 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66dfedbd37492ff42246d71926f5917663073239444456d7e85f4912a78ad1e2
4
- data.tar.gz: 326db7d6c6f575f2a6e754fd549f13862ef392122f15493979d099ec2e96b38e
3
+ metadata.gz: 25621c837fd7effe9227d019d92fb0cf73c8892b4a9e77b3723a9d160f0457c7
4
+ data.tar.gz: 205c3ebcfcd1a77cbe48a4f7649a64e9bc7a2aa69fd3913cc8839fbb08623187
5
5
  SHA512:
6
- metadata.gz: 79781530986da18cf8b138c6a031e293a2b94dbfbca08b370e191f142458c59af5984fe19216e288e63877db3ad5583382dabdd580c8de1fa67c9481a424e223
7
- data.tar.gz: c7a780dd06c7fed0e6e486ae9f3ce9eb2bf974321813ccfd0e5c3a0022007e1779f54b06e2d8999492b325873f227f1eef5032efb9ff41a6ecae24fdd4651b29
6
+ metadata.gz: 93bb6a14918c6b702fb18985966a00628383b68453572545949b402e44c142b22ab580a2ecf021a2ecb74718f8a950005f7e7915d839a26b23095a9603835f50
7
+ data.tar.gz: 79e3353ed13b1c8320f6f8525a171b16252a96d7f8639d1cbc1eda9a7b1bb9ba0645a1e28234b5d1a335e36beb1505906e52a7b356645a5fc90a72122a97f62b
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ <!--
2
+ # @title README - mod: assets
3
+ -->
4
+
5
+ # Assets mod
6
+
7
+ This mod unifies handling of styles (CSS, SCSS, etc) and scripts
8
+ (JavaScript, CoffeeScript, etc).
9
+
10
+ For both styles and scripts, the idea is to output optimized files for
11
+ browser caching and thus improve users' experience by reducing loading times. In other
12
+ words, we use a wide variety of asset sources to assemble a ready-for-prime-time
13
+ .js and .css files.
14
+
15
+ There are two main kinds of cards in the asset pipeline: inputters (where
16
+ the code comes from) and outputters (where it ends up).
17
+
18
+ ## Inputters
19
+
20
+ Inputters are can be created in multiple ways:
21
+
22
+ 1. By adding code to the assets directory in a mod
23
+ 2. By adding remote and/or local assets to a manifest.yml file
24
+ 3. By combining other inputters
25
+ 4. By directly creating cards of an inputter type
26
+
27
+ ### adding code to the assets directory
28
+
29
+ Each mod can have an `assets` directory with `style` and `script` subdirectories.
30
+ By adding CSS or SCSS files to `assets/style` (or JavaScript or CoffeeScript
31
+ files to `assets/script`) to a mod in use, your code will automatically be included
32
+ in standard asset output.
33
+
34
+ After adding the first asset to a mod, you may need to run `rake card:mod:install` (or
35
+ the more comprehensive `decko update`) for the change to take effect. Otherwise,
36
+ everything should pretty much handle itself.
37
+
38
+ By default, the load order within a mod is alphabetical, and the load order across mods
39
+ is governed by the mod load order, which can be seen using `rake card:mod:list`.
40
+
41
+ ### using manifest.yml files
42
+
43
+ If you want to customize the load order of asset files, you can add a `manifest.yml`
44
+ file to `assets/style` or `assets/script`.
45
+
46
+ For example, consider these lines from the manifest.yml file in the bootstrap mod:
47
+
48
+ libraries:
49
+ items:
50
+ - font_awesome.css
51
+ - material_icons.css
52
+ - bootstrap_colorpicker.scss
53
+ - ../../vendor/bootstrap-colorpicker/src/sass/_colorpicker.scss
54
+
55
+ The word `libraries` is an arbitrary name for the manifest group; you can use any name
56
+ (other than `remote`) as long as it isn't duplicated in the file. The `items` specify
57
+ the load order for this manifest group.
58
+
59
+ Note that the manifest also makes it possible to include source files that are not in
60
+ the assets directory using relative path references.
61
+
62
+ Manifests also make it possible to include remote files. For example:
63
+
64
+ remote:
65
+ items:
66
+ - src: https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.1/js/select2.full.min.js
67
+ integrity: ...
68
+ referrerpolicy: no-referrer
69
+ crossorigin: anonymous
70
+
71
+ ### combining other inputters
72
+
73
+ There are various special cards that combine inputters and are inputters themselves:
74
+
75
+ - the `:style_mods` card contains all the standard assets from mods' asset directories
76
+ - _Skin_ cards combine a particular set of styles
77
+ - `(Mod)+:style` and `(Mod)+:script` assemble the assets for a given mod
78
+
79
+ ### creating inputter cards
80
+
81
+ Many Cardtypes are coded to be inputters. If you create a card with the type CSS,
82
+ for example, it will automatically be treated as an inputter. The same goes for SCSS,
83
+ CoffeeScript, and JavaScript cards. (In code terms, this is achieved by having those
84
+ sets include the `Abstract::AssetInputter` set).
85
+
86
+ Because these cards are intended for Sharks, they are predominantly documented on
87
+ decko.org
88
+
89
+ ## Outputters
90
+
91
+ Outputters produce the final asset (.js and .css) files delivered to users' browsers.
92
+
93
+ They work slightly differently with style and script cards. JavaScript (.js) output is
94
+ produced on a mod-by-mod basis. The `:all+:script` rule maintains a list of all mods
95
+ with script inputters, and output is produced for each mod that assembles all the
96
+ javascript for that mod. The output is managed with a file card using the name pattern
97
+ `MOD+:asset_ouput`
98
+
99
+ With style cards, SCSS variables are often shared across many mods, so the output CSS
100
+ cannot be constructed on a mod-by-mod basis; it has to be generated across all mods at
101
+ once. Thus the site's main CSS is served as a single file associated with `:all+:style`,
102
+ which typically points to a skin card. The output is managed as a file card at
103
+ `:all+:style+:asset_output`.
104
+
105
+ ### generating output from input
106
+
107
+ For each inputter, we generate a VirtualCache card following this pattern:
108
+ `(Inputter)+:asset_input`. This card processes the inputs as much as it safely can.
109
+ For example, SCSS cards cannot be converted to CSS here, because they often
110
+ involve variables that must be used by other inputters.
111
+
112
+ When changes to inputters are detected, they trigger changes to all inputters and
113
+ outputters that depend on them.
114
+
data/data/real.yml ADDED
@@ -0,0 +1,7 @@
1
+ - :name: "*asset input"
2
+ :codename: asset_input
3
+ - :name: "*asset output"
4
+ :codename: asset_output
5
+ - :name: Remote manifest group
6
+ :type: :cardtype
7
+ :codename: remote_manifest_group
@@ -43,9 +43,6 @@ class DeathToMachines < Cardio::Migration::Core
43
43
  delete_group_card
44
44
  delete_old_style_cards
45
45
 
46
- ensure_code_card "*asset input"
47
- ensure_code_card "*asset output"
48
-
49
46
  drop_all_style_items
50
47
  update_mod_asset_type_id
51
48
 
data/lib/card/assets.rb CHANGED
@@ -15,8 +15,8 @@ class Card
15
15
  ]
16
16
  end
17
17
 
18
- def refresh_assets force: false
19
- return unless force || refresh_assets?
18
+ def refresh force: false
19
+ return unless force || refresh?
20
20
 
21
21
  inputters = standard_inputters
22
22
 
@@ -30,6 +30,15 @@ class Card
30
30
  generate_asset_output_files if force
31
31
  end
32
32
 
33
+ def wipe
34
+ Auth.as_bot do
35
+ %i[asset_input asset_output].each do |field|
36
+ Card.search(right: field).each(&:delete!)
37
+ Virtual.where(right_id: field.card_id).destroy_all
38
+ end
39
+ end
40
+ end
41
+
33
42
  def make_output_coded
34
43
  asset_outputters.each(&:make_asset_output_coded)
35
44
  end
@@ -72,7 +81,7 @@ class Card
72
81
  Card.search type_id: inputter_types.unshift("in")
73
82
  end
74
83
 
75
- def refresh_assets?
84
+ def refresh?
76
85
  case Cardio.config.asset_refresh
77
86
  when :eager then true
78
87
  when :cautious then cautious_refresh?
@@ -0,0 +1,20 @@
1
+ namespace :card do
2
+ namespace :assets do
3
+ desc "regenerate asset outputs"
4
+ task refresh: :environment do
5
+ Card::Assets.refresh force: true
6
+ end
7
+
8
+ desc "update coded asset outputs"
9
+ task code: :environment do
10
+ Cardio.config.compress_assets = true
11
+ Card::Cache.reset_all
12
+ Card::Assets.make_output_coded
13
+ end
14
+
15
+ desc "delete all cached asset outputs and inputs"
16
+ task wipe: :environment do
17
+ Card::Assets.wipe
18
+ end
19
+ end
20
+ end
@@ -59,7 +59,7 @@ format :html do
59
59
  end
60
60
 
61
61
  def short_content
62
- fa_icon("exclamation-circle", class: "text-muted pr-2") +
62
+ icon_tag(:warning, class: "text-muted pe-2") +
63
63
  wrap_with(:span, "asset file", class: "text-muted")
64
64
  end
65
65
  end
@@ -1,4 +1,4 @@
1
- card_accessor :asset_input, type_id: Card::PlainTextID
1
+ card_accessor :asset_input, type: :plain_text
2
2
 
3
3
  def dependent_asset_inputters
4
4
  referers_responding_to :asset_input
@@ -12,11 +12,13 @@ def referers_responding_to method_name
12
12
  referers.select { |referer| referer.respond_to? method_name }
13
13
  end
14
14
 
15
- event :asset_input_changed, :finalize, on: :save do
15
+ event :asset_input_changed, :finalize,
16
+ on: :save, when: :asset_inputter?, skip: :allowed do
16
17
  update_asset_input
17
18
  end
18
19
 
19
- event :asset_input_changed_on_delete, :finalize, on: :delete, before: :clear_references do
20
+ event :asset_input_changed_on_delete, :finalize,
21
+ on: :delete, when: :asset_inputter?, before: :clear_references do
20
22
  update_referers_after_input_changed
21
23
  end
22
24
 
@@ -33,19 +35,19 @@ def update_asset_input
33
35
  # otherwise the migration that adds the asset_input card fails
34
36
 
35
37
  Card::Auth.as_bot do
36
- asset_input_card.update content: render_asset_input_content
38
+ asset_input_card.update({})
37
39
  update_referers_after_input_changed
38
40
  end
39
41
  end
40
42
 
41
43
  def asset_input_content
42
- return render_asset_input_content if virtual?
44
+ return assemble_asset_input_content if virtual?
43
45
  update_asset_input if asset_input.blank?
44
46
  asset_input
45
47
  end
46
48
 
47
- def render_asset_input_content
48
- format(input_format).render(input_view)
49
+ def assemble_asset_input_content
50
+ format(input_format).render input_view
49
51
  end
50
52
 
51
53
  def input_view
@@ -64,6 +66,11 @@ def asset_input_needs_refresh?
64
66
  false
65
67
  end
66
68
 
69
+ # for override
70
+ def asset_inputter?
71
+ true
72
+ end
73
+
67
74
  format :html do
68
75
  def edit_success
69
76
  { reload: true }
@@ -1,11 +1,8 @@
1
1
  include_set Abstract::Lock
2
+ include Env::Location
2
3
 
3
4
  card_accessor :asset_output, type: :file
4
5
 
5
- def output_filetype
6
- output_format
7
- end
8
-
9
6
  event :update_asset_output_file, :finalize, on: :save do
10
7
  update_asset_output
11
8
  end
@@ -54,7 +51,7 @@ def store_output output
54
51
  end
55
52
 
56
53
  def handle_file output
57
- file = Tempfile.new [id.to_s, ".#{output_filetype}"]
54
+ file = Tempfile.new [id.to_s, ".#{output_format}"]
58
55
  file.write output
59
56
  file.close
60
57
  yield file
@@ -1,4 +1,4 @@
1
- include_set Abstract::Pointer
1
+ include_set Abstract::List
2
2
  include_set Abstract::ReadOnly
3
3
 
4
4
  def item_cards _args={}
@@ -80,12 +80,14 @@ def manifest_group_minimize? group_name
80
80
  end
81
81
 
82
82
  def manifest
83
+ # FIXME: sometimes this needs to get cleared!
83
84
  @manifest ||= load_manifest
84
85
  end
85
86
 
86
87
  def load_manifest
87
88
  return unless manifest_exists?
88
89
  manifest = YAML.load_file manifest_path
90
+ return {} unless manifest # blank manifest
89
91
  validate_manifest manifest
90
92
  manifest
91
93
  end
@@ -115,13 +117,12 @@ def source_changed? since:
115
117
  folder_group_card&.paths&.map { |path| File.mtime(path) }
116
118
  end
117
119
 
118
- return unless source_updates.present?
119
-
120
- source_updates.max > since
120
+ source_updates.present? && (source_updates.max > since)
121
121
  end
122
122
 
123
123
  def manifest_updated_at
124
124
  return unless manifest_exists?
125
+
125
126
  File.mtime(manifest_path)
126
127
  end
127
128
 
@@ -153,3 +154,12 @@ end
153
154
  def raise_manifest_error msg
154
155
  raise Card::Error, "invalid manifest format in #{manifest_path}: #{msg}"
155
156
  end
157
+
158
+ format :html do
159
+ def map_remote_items
160
+ remote_items = card.manifest_group_items "remote"
161
+ return unless remote_items
162
+
163
+ remote_items.map { |args| yield args.clone }
164
+ end
165
+ end
@@ -1,7 +1,7 @@
1
1
  include_set Abstract::VirtualCache
2
2
 
3
3
  def virtual_content
4
- left.render_asset_input_content
4
+ left.assemble_asset_input_content
5
5
  end
6
6
 
7
7
  def history?
@@ -10,9 +10,7 @@ def history?
10
10
  false
11
11
  end
12
12
 
13
- event :remove_codename, :prepare_to_validate,
14
- on: :delete,
15
- when: proc { |c| c.codename.present? } do
13
+ event :remove_codename, :prepare_to_validate, on: :delete, when: :codename? do
16
14
  # load file before deleting codename otherwise it will fail later
17
15
  attachment
18
16
  self.codename = nil
@@ -20,7 +18,7 @@ end
20
18
 
21
19
  format do
22
20
  def outputter
23
- left
21
+ card.left
24
22
  end
25
23
 
26
24
  view :not_found do
data/set/type/mod.rb CHANGED
@@ -6,59 +6,15 @@ def modname
6
6
  codename.to_s.gsub(/^mod_/, "")
7
7
  end
8
8
 
9
- def ensure_mod_script_card
10
- ensure_mod_asset_card :script
11
- end
12
-
13
- def ensure_mod_style_card
14
- ensure_mod_asset_card :style
15
- end
16
-
17
- private
18
-
19
9
  def ensure_mod_asset_card asset_type
20
10
  asset_card = fetch_mod_assets_card asset_type
21
- return if asset_card.no_action?
22
- asset_card.save! if asset_card.new? || asset_card.codename.blank?
23
-
24
- if asset_card.content?
25
- add_mod_asset_card asset_type
26
- asset_card.refresh_asset
27
- else
28
- puts "Drop: #{asset_card.name}"
29
- drop_mod_asset_card asset_type, asset_card
30
- end
11
+ return unless asset_card.assets_path
12
+ asset_card.save! if asset_card.new?
13
+ asset_card.name
31
14
  end
32
15
 
33
- def add_mod_asset_card asset_type
34
- target = asset_type == :style ? Card[:style_mods] : all_rule(asset_type)
35
- target.add_item! codename_for(asset_type)
36
- end
37
-
38
- def drop_mod_asset_card asset_type, asset_card
39
- asset_card.update codename: nil
40
- asset_card.delete
41
- all_rule(asset_type).drop_item! asset_card
42
- end
43
-
44
- def codename_for asset_type
45
- [codename, asset_type]
46
- end
47
-
48
- def all_rule asset_type
49
- Card[:all, asset_type]
50
- end
16
+ private
51
17
 
52
18
  def fetch_mod_assets_card asset_type
53
- codename = codename_for asset_type
54
- if Card::Codename.exists? codename
55
- Card[codename.to_sym]
56
- else
57
- card = Card.fetch [name, asset_type], new: {
58
- type_id: Card::ListID, codename: codename
59
- }
60
- card.codename = codename
61
- card.type_id = Card::ListID
62
- card
63
- end
19
+ Card.fetch [name, asset_type], new: { type: :list }
64
20
  end
@@ -1,6 +1,8 @@
1
1
  include_set Abstract::ReadOnly
2
2
  include_set Abstract::ManifestGroup
3
3
 
4
+ basket[:non_createable_types] << :remote_manifest_group
5
+
4
6
  def local?
5
7
  @local = false
6
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-08 00:00:00.000000000 Z
13
+ date: 2023-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.104.2
21
+ version: 1.105.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.104.2
28
+ version: 1.105.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: execjs
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -52,70 +52,70 @@ dependencies:
52
52
  requirements:
53
53
  - - '='
54
54
  - !ruby/object:Gem::Version
55
- version: 0.14.2
55
+ version: 0.15.1
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: 0.14.2
62
+ version: 0.15.1
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: card-mod-format
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.14.2
69
+ version: 0.15.1
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - '='
75
75
  - !ruby/object:Gem::Version
76
- version: 0.14.2
76
+ version: 0.15.1
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: card-mod-list
79
79
  requirement: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - '='
82
82
  - !ruby/object:Gem::Version
83
- version: 0.14.2
83
+ version: 0.15.1
84
84
  type: :runtime
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - '='
89
89
  - !ruby/object:Gem::Version
90
- version: 0.14.2
90
+ version: 0.15.1
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: card-mod-carrierwave
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - '='
96
96
  - !ruby/object:Gem::Version
97
- version: 0.14.2
97
+ version: 0.15.1
98
98
  type: :runtime
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - '='
103
103
  - !ruby/object:Gem::Version
104
- version: 0.14.2
104
+ version: 0.15.1
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: card-mod-content
107
107
  requirement: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - '='
110
110
  - !ruby/object:Gem::Version
111
- version: 0.14.2
111
+ version: 0.15.1
112
112
  type: :runtime
113
113
  prerelease: false
114
114
  version_requirements: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - '='
117
117
  - !ruby/object:Gem::Version
118
- version: 0.14.2
118
+ version: 0.15.1
119
119
  description: ''
120
120
  email:
121
121
  - info@decko.org
@@ -123,11 +123,13 @@ executables: []
123
123
  extensions: []
124
124
  extra_rdoc_files: []
125
125
  files:
126
- - db/migrate_core_cards/20200806112346_add_mod_type.rb
126
+ - README.md
127
+ - config/locales/de.yml
128
+ - config/locales/en.yml
129
+ - data/real.yml
127
130
  - db/migrate_core_cards/202108028112352_death_to_machines.rb
128
131
  - lib/card/assets.rb
129
- - locales/de.yml
130
- - locales/en.yml
132
+ - lib/tasks/card/assets.rake
131
133
  - set/abstract/01_manifest_group.rb
132
134
  - set/abstract/asset_file.rb
133
135
  - set/abstract/asset_group.rb
@@ -150,6 +152,7 @@ metadata:
150
152
  wiki_uri: https://decko.org
151
153
  documentation_url: http://docs.decko.org/
152
154
  card-mod: assets
155
+ card-mod-group: gem-defaults
153
156
  post_install_message:
154
157
  rdoc_options: []
155
158
  require_paths:
@@ -165,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
168
  - !ruby/object:Gem::Version
166
169
  version: '0'
167
170
  requirements: []
168
- rubygems_version: 3.2.15
171
+ rubygems_version: 3.3.11
169
172
  signing_key:
170
173
  specification_version: 4
171
174
  summary: decko asset pipeline
@@ -1,13 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- class AddModType < Cardio::Migration::Core
4
- def up
5
- add_cardtypes
6
- Card::Cache.reset_all
7
- end
8
-
9
- def add_cardtypes
10
- ensure_code_card name: "Remote manifest group", type_id: Card::CardtypeID
11
- ensure_code_card name: "Mod", type_id: Card::CardtypeID
12
- end
13
- end
File without changes
File without changes