Module: Card::Set::Abstract::AssetOutputter

Extended by:
Card::Set
Includes:
Env::Location
Defined in:
platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb

Overview

Set: Abstract (AssetOutputter)

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset

Methods included from I18nScope

#mod_name, #scope

Methods included from Registrar

#extended, #finalize_load, #process_base_modules, #register_set

Methods included from Helpers

#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name

Methods included from Card::Set::AdvancedApi

#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Methods included from Env::Location

#card_path, #card_url, #cardname_from_url, #relative_url_root

Class Method Details

.source_locationObject



7
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/mod/assets/set/abstract/asset_outputter.rb"; end

Instance Method Details

#asset_output_codenameObject



82
83
84
85
86
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 82

def asset_output_codename
  asset_output_card.name.parts.map do |part|
    Card[part].codename&.to_s || part.cardname.safe_key
  end.join "_"
end

#asset_output_pathObject



98
99
100
101
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 98

def asset_output_path
  # ensure_asset_output
  asset_output_card.file&.path
end

#asset_output_urlObject



92
93
94
95
96
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 92

def asset_output_url
  # ensure_asset_output
  asset_output_card.file&.url # (:default, timestamp: false)
  # to get rid of additional number in url
end

#event: update_asset_output_fileObject



13
14
15
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 13

event :update_asset_output_file, :finalize, on: :save do
  update_asset_output
end

#event: validate_asset_inputsObject



17
18
19
20
21
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 17

event :validate_asset_inputs, :validate, on: :save, skip: :allowed do
  return unless (invalid_input = find_invalid_input)

  errors.add :content, t(:assets_invalid_input, input_name: invalid_input.name)
end

#find_invalid_inputObject



23
24
25
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 23

def find_invalid_input
  item_cards.find { |c| !c.respond_to?(:asset_input_content) }
end

#handle_file(output) {|file| ... } ⇒ Object

Yields:

  • (file)


60
61
62
63
64
65
66
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 60

def handle_file output
  file = Tempfile.new [id.to_s, ".#{output_format}"]
  file.write output
  file.close
  yield file
  file.unlink
end

#input_from_item_cards(joint = "\n") ⇒ Object



39
40
41
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 39

def input_from_item_cards joint="\n"
  input_item_cards.map(&:asset_input_content).compact.join(joint)
end

#input_item_cardsObject



88
89
90
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 88

def input_item_cards
  item_cards(known_only: true).compact.reject(&:trash)
end

#make_asset_output_coded(mod) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 72

def make_asset_output_coded mod
  mod ||= :assets
  Card::Auth.as_bot do
    ENV["STORE_CODED_FILES"] = "true"
    asset_output_card.update! storage_type: :coded, mod: mod,
                              codename: asset_output_codename
    ENV["STORE_CODED_FILES"] = nil
  end
end

#store_output(output) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 43

def store_output output
  handle_file(output) do |file|
    Card::Auth.as_bot do
      # FIXME: this is definitely not how we want to do this.
      # problem is that file object is getting stashed in set_specific attributes,
      # and then reassigned later. This causes problems in cases where a single
      # card (eg *all+*style) is updated by multiple inputters, because the old file arg
      # sticks around in the set specific stash and then reemerges after it's been
      # unlinked. we need a more general solution
      # (error reproducible eg when running card:mod:install on wikirate)
      aoc = asset_output_card
      aoc.update file: file
      aoc.set_specific.delete :file
    end
  end
end

#update_asset_outputObject



27
28
29
30
31
32
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 27

def update_asset_output
  # puts "update_asset_output called: #{name}"
  lock do
    store_output input_from_item_cards
  end
end

#update_asset_output_liveObject



34
35
36
37
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 34

def update_asset_output_live
  update_asset_output
  card_path asset_output_url
end

#view: asset_output_urlObject



68
69
70
# File 'platypus/tmp/set/gem-defaults/mod018-assets/abstract/asset_outputter.rb', line 68

view :asset_output_url do
  asset_output_url
end