diff --git a/set/mod001-admin/self/admin.rb b/set/mod001-admin/self/admin.rb deleted file mode 100644 index 1043947..0000000 --- a/set/mod001-admin/self/admin.rb +++ /dev/null @@ -1,155 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Admin" -# -# collect arrays of the form -module Admin; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/admin/set/self/admin.rb"; end -# [task symbol, { execute_policy: block, stats_policy: block }] -basket :tasks - -def run_task_from_task_basket task - task = task.to_sym - task_data = tasks.find { |h| h[:name].to_sym == task.to_sym } - if !irreversibles_tasks_allowed? && task_data[:irreversible] - not_allowed task_data[:stats][:link_text] - elsif task_data - task_data[:execute_policy].call - end -end - -event :admin_tasks, :initialize, on: :update do - return unless (task = Env.params[:task]) - raise Card::Error::PermissionDenied, self unless Auth.always_ok? - - case task.to_sym - when :clear_cache then Card::Cache.reset_all - when :repair_references then Card::Reference.repair_all - when :repair_permissions then Card.repair_all_permissions - when :clear_solid_cache then Card.clear_solid_cache - when :clear_machine_cache then Card.reset_all_machines - when :clear_script_cache then Card.reset_script_machine - when :clear_history - not_allowed "clear history" unless irreversibles_tasks_allowed? - Card::Action.delete_old - else - run_task_from_task_basket task - end - abort :success -end - -def not_allowed task - raise Card::Error::PermissionDenied, - "The admin task '#{task}' is disabled for security reasons.
"\ - "You can enable it with the config option 'allow_irreversible_admin_tasks'" -end - -def irreversibles_tasks_allowed? - Cardio.config.allow_irreversible_admin_tasks -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core, cache: :never do - stats = card_stats - stats += cache_stats - stats += memory_stats - card.tasks.each do |task| - stats += Array.wrap task[:stats] - end - table_content = stats.map { |args| stat_row(args) } - table table_content, header: %w[Stat Value Action] - end - - def card_stats - [ - { title: "cards", - count: Card.where(trash: false) }, - { title: "actions", - count: Card::Action }, - # link_text: "clear history", - # task: "clear_history" }, - { title: "references", - count: Card::Reference } - # link_text: "repair all", - # task: "repair_references" } - ] - end - - def cache_stats - [ - { title: "solid cache", - count: solid_cache_count, unit: " cards", - link_text: "clear solid cache", - task: "clear_solid_cache" }, - { title: "machine cache", - count: machine_cache_count, unit: " cards", - link_text: "clear machine cache", - task: "clear_machine_cache" } - ] - # return stats unless Card.config.view_cache# - # stats << { title: "view cache", - # count: Card::View, - # link_text: "clear view cache", - # task: "clear_view_cache" } - end - - def memory_stats - oldmem = session[:memory] - session[:memory] = newmem = card.profile_memory - stats = [ - { title: "memory now", - count: newmem, unit: "M", - link_text: "clear cache", task: "clear_cache" } - ] - return stats unless oldmem - - stats << { title: "memory prev", count: oldmem, unit: "M" } - stats << { title: "memory diff", count: newmem - oldmem, unit: "M" } - stats - end - - def stat_row args={} - res = [(args[:title] || "")] - res << "#{count(args[:count])}#{args[:unit]}" - return res unless args[:task] - - res << link_to_card(:admin, (args[:link_text] || args[:task]), - path: { action: :update, task: args[:task] }) - res - end - - def count counter - counter = counter.call if counter.is_a?(Proc) - counter.respond_to?(:count) ? counter.count : counter - end - - def solid_cache_count - Card.search right: { codename: "solid_cache" }, return: "count" - end - - def machine_cache_count - Card::Virtual.where(right_id: MachineCacheID).count - end - - def delete_sessions_link months - link_to_card :admin, months, path: { action: :update, months: months, - task: "delete_old_sessions" } - end -end - -def current_memory_usage - `ps -o rss= -p #{Process.pid}`.to_i -end - -def profile_memory &block - before = current_memory_usage - if block_given? - instance_eval(&block) - else - before = 0 - end - (current_memory_usage - before) / 1024.to_i -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/admin/set/self/admin.rb ~~ diff --git a/set/mod001-admin/self/admin_info.rb b/set/mod001-admin/self/admin_info.rb deleted file mode 100644 index a44d5d3..0000000 --- a/set/mod001-admin/self/admin_info.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "AdminInfo" -# -module AdminInfo; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/admin/set/self/admin_info.rb"; end -basket :warnings - -# For each warning in the basket (eg :my_warning), the core view -# will run a test by appending a question mark (eg #my_warning?). -# If it fails it will generate a message by appending message -# (eg #my_warning_message). - -add_to_basket :warnings, :no_email_delivery - -def no_email_delivery? - Card.config.action_mailer.perform_deliveries == false -end - -def clean_html? - false -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core do - warnings = card.warnings.map do |warning| - card.send("#{warning}?") ? send("#{warning}_message") : nil - end - warnings.compact! - warnings.empty? ? "" : warning_alert(warnings) - end - - def warning_alert warnings - # 'ADMINISTRATOR WARNING' - alert :warning, true do - "
#{t :admin_warn}
" + list_tag(warnings) - end - end - - def no_email_delivery_message - # "Email delivery is turned off." - # "Change settings in config/application.rb to send sign up notifications." - t :admin_email_off, path: "config/application.rb" - end - - def warning_list_with_auto_scope warnings - "
#{t :admin_warn}
" + warnings.join("\n") - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/admin/set/self/admin_info.rb ~~ diff --git a/set/mod001-admin/self/debugger.rb b/set/mod001-admin/self/debugger.rb deleted file mode 100644 index b847006..0000000 --- a/set/mod001-admin/self/debugger.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Debugger" -# -module Debugger; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/admin/set/self/debugger.rb"; end -def raw_help_text - "show more useful error pages" -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/admin/set/self/debugger.rb ~~ diff --git a/set/mod002-core/all/abort.rb b/set/mod002-core/all/abort.rb deleted file mode 100644 index e0fd39c..0000000 --- a/set/mod002-core/all/abort.rb +++ /dev/null @@ -1,85 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Abort) -# -# The Card#abort method is for cleanly exiting an action without continuing -# to process any further events. -# -# Three statuses are supported: -# -module Abort; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/abort.rb"; end -# failure: adds an error, returns false on save -# success: no error, returns true on save -# triumph: similar to success, but if called on a subcard -# it causes the entire action to abort (not just the subcard) -def abort status, msg="action canceled" - director.abort - if status == :failure && errors.empty? - errors.add :abort, msg - elsif status.is_a?(Hash) && status[:success] - success << status[:success] - status = :success - end - raise Card::Error::Abort.new(status, msg) -end - -def aborting - yield - errors.any? ? abort(:failure) : abort(:success) -end - -def abortable - yield -rescue Card::Error::Abort => e - handle_abort_error e -end - -private - -def handle_abort_error e - case e.status - when :triumph - @supercard ? raise(e) : true - when :success - abort_success - end -end - -def abort_success - if @supercard - @supercard.subcards.delete key - @supercard.director.subdirectors.delete self - expire :soft - end - true -end - -# this is an override of standard rails behavior that rescues abort -# makes it so that :success abortions do not rollback -def with_transaction_returning_status &block - status = nil - self.class.transaction do - add_to_transaction - remember_transaction_record_state - status = abortable(&block) - raise ActiveRecord::Rollback unless status - end - status -end - -# FIXME: these two do not belong here! - -public - -event :notable_exception_raised do - error = Card::Error.current - Rails.logger.debug "#{error.message}\n#{error.backtrace * "\n "}" -end - -def success - Env.success(name) -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/abort.rb ~~ diff --git a/set/mod002-core/all/assign_attributes.rb b/set/mod002-core/all/assign_attributes.rb deleted file mode 100644 index 8b9e588..0000000 --- a/set/mod002-core/all/assign_attributes.rb +++ /dev/null @@ -1,119 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (AssignAttributes) -# -module AssignAttributes; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/assign_attributes.rb"; end -include Card::Subcards::Args - -def assign_attributes args={} - args = prepare_assignment_args args - - assign_with_subcards args do - assign_with_set_modules args do - super prepare_assignment_params(args) - end - end -end - -def assign_set_specific_attributes - set_specific.each_pair do |name, value| - send "#{name}=", value - end -end - -protected - -module ClassMethods - def assign_or_newish name, attributes, fetch_opts={} - if (known_card = Card.fetch(name, fetch_opts)) - known_card.refresh.newish attributes - known_card - else - Card.new attributes.merge(name: name) - end - end -end - -def prepare_assignment_params args - args = args.to_unsafe_h if args.respond_to?(:to_unsafe_h) - params = ActionController::Parameters.new(args) - params.permit! - params[:db_content] = standardize_content(params[:db_content]) if params[:db_content] - params -end - -def prepare_assignment_args args - return {} unless args - - args = args.symbolize_keys - normalize_type_attributes args - stash_set_specific_attributes args - args -end - -def assign_with_set_modules args - return yield unless args[:name] || args[:type_id] - - refresh_set_modules { yield } -end - -def assign_with_subcards args - subcard_args = extract_subcard_args! args - yield - subcards.add subcard_args if subcard_args.present? -end - -def refresh_set_modules - reinclude_set_modules = @set_mods_loaded - yield - reset_patterns - include_set_modules if reinclude_set_modules -end - -def stash_set_specific_attributes args - @set_specific = {} - Card.set_specific_attributes.each do |key| - set_specific[key] = args.delete(key) if args.key?(key) - end -end - -def normalize_type_attributes args - new_type_id = extract_type_id! args unless args.delete(:type_lookup) == :skip - args[:type_id] = new_type_id if new_type_id -end - -def extract_type_id! args={} - case - when (type_id = args.delete(:type_id)&.to_i) - type_id.zero? ? nil : type_id - when (type_code = args.delete(:type_code)&.to_sym) - type_id_from_codename type_code - when (type_name = args.delete :type) - type_id_from_cardname type_name - end -end - -def type_id_from_codename type_code - type_id_or_error(type_code) { Card::Codename.id type_code } -end - -def type_id_from_cardname type_name - type_id_or_error(type_name) { type_name.card_id } -end - -def type_id_or_error val - type_id = yield - return type_id if type_id - - errors.add :type, "#{val} is not a known type." - nil -end - -# 'set' refers to the noun not the verb -def set_specific - @set_specific ||= {} -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/assign_attributes.rb ~~ diff --git a/set/mod002-core/all/autoname.rb b/set/mod002-core/all/autoname.rb deleted file mode 100644 index e5315c3..0000000 --- a/set/mod002-core/all/autoname.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Autoname) -# -module Autoname; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/autoname.rb"; end -event :set_autoname, :prepare_to_store, on: :create, when: :autoname? do - self.name = autoname rule(:autoname) - autoname_card = rule_card :autoname - autoname_card.update_column :db_content, name - autoname_card.expire - pull_from_trash! - Card.write_to_soft_cache self -end - -def no_autoname? - !autoname? -end - -def autoname? - name.blank? && - (@autoname_rule.nil? ? (@autoname_rule = rule(:autoname).present?) : @autoname_rule) -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/autoname.rb ~~ diff --git a/set/mod002-core/all/codename.rb b/set/mod002-core/all/codename.rb deleted file mode 100644 index e351b4e..0000000 --- a/set/mod002-core/all/codename.rb +++ /dev/null @@ -1,39 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Codename) -# -module Codename; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/codename.rb"; end -def codename - super&.to_sym -end - -event :validate_codename, :validate, on: :update, changed: :codename do - validate_codename_permission - validate_codename_uniqueness -end - -event :reset_codename_cache, :integrate, changed: :codename do - return if action == :create && codename.nil? - - Card::Codename.reset_cache - Card::Codename.generate_id_constants -end - -private - -def validate_codename_permission - return if Auth.always_ok? || Auth.as_id == creator_id - - errors.add :codename, t(:core_only_admins_codename) -end - -def validate_codename_uniqueness - return (self.codename = nil) if codename.blank? - return if errors.present? || !Card.find_by_codename(codename) - - errors.add :codename, t(:core_error_code_in_use, codename: codename) -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/codename.rb ~~ diff --git a/set/mod002-core/all/collection.rb b/set/mod002-core/all/collection.rb deleted file mode 100644 index 1ff0e03..0000000 --- a/set/mod002-core/all/collection.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Collection) -# -# shared methods for card collections (Pointers, Searches, Sets, etc.) -module Collection; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/collection.rb"; end -module ClassMethods - def search spec, comment=nil, &block - results = ::Card::Query.run(spec, comment) - results.each(&block) if block_given? && results.is_a?(Array) - results - end - - def count_by_cql spec - spec = spec.clone - spec.delete(:offset) - search spec.merge(return: "count") - end - - def find_each options={}, &block - # this is a copy from rails (3.2.16) and is needed because this - # is performed by a relation (ActiveRecord::Relation) - find_in_batches(options) do |records| - records.each(&block) - end - end - - def find_in_batches options={} - if block_given? - super(options) do |records| - yield(records) - Card::Cache.reset_soft - end - else - super(options) - end - end -end - -def collection? - item_cards != [self] -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :count do - card.item_names.size - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :carousel do - bs_carousel unique_id, 0 do - nest_item_array.each do |rendered_item| - item(rendered_item) - end - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/collection.rb ~~ diff --git a/set/mod002-core/all/content.rb b/set/mod002-core/all/content.rb deleted file mode 100644 index 5c96421..0000000 --- a/set/mod002-core/all/content.rb +++ /dev/null @@ -1,74 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Content) -# -module Content; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/content.rb"; end -event :set_content, :store, on: :save do - self.db_content = prepare_db_content - @selected_action_id = @selected_content = nil - clear_drafts -end - -event :save_draft, :store, on: :update, when: :draft? do - save_content_draft content - abort :success -end - -event :set_default_content, - :prepare_to_validate, - on: :create, when: :use_default_content? do - self.db_content = template.db_content -end - -def draft? - Env.params["draft"] == "true" -end - -def clean_html? - true -end - -def use_default_content? - !db_content_changed? && template && template.db_content.present? -end - -def unfilled? - blank_content? && blank_comment? && !subcards? -end - -def blank_comment? - comment.blank? || comment.strip.blank? -end - -def prepare_db_content - cont = standard_db_content || "" # necessary? - clean_html? ? Card::Content.clean!(cont) : cont -end - -def standard_db_content - if structure - # do not override db_content with content from structure - db_content - else - standard_content - end -end - -# seems like this should be moved to format so we can fall back on title -# rather than name. (In fact, name, title, AND label is a bit much. -# Trim to 2?) -def label - name -end - -def creator - Card[creator_id] -end - -def updater - Card[updater_id] -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/content.rb ~~ diff --git a/set/mod002-core/all/debug.rb b/set/mod002-core/all/debug.rb deleted file mode 100644 index ba8507b..0000000 --- a/set/mod002-core/all/debug.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Debug) -# -module Debug; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/debug.rb"; end -def to_s - "#<#{self.class.name}[#{debug_type}]#{attributes['name']}>" -end - -def inspect - error_messages = errors.any? ? "" : "" - "# 255 - errors.add :name, t(:core_error_too_long, length: name.length) - elsif name.blank? - errors.add :name, t(:core_error_blank_name) - elsif name_incomplete? - errors.add :name, t(:core_is_incomplete) - elsif !name.valid? - errors.add :name, t(:core_error_banned_characters, - banned: Card::Name.banned_array * " ") - elsif changing_existing_tag_to_compound? - errors.add :name, t(:core_error_name_tag, name: name) - end -end - -event :validate_key, after: :validate_name, on: :save, when: :no_autoname? do - if key.empty? - errors.add :key, t(:core_error_blank_key) if errors.empty? - elsif key != name.key - errors.add :key, t(:core_error_wrong_key, key: key, name: name) - end -end - -event :validate_renaming, :validate, on: :update, changed: :name, skip: :allowed do - return if name_before_act&.to_name == name # just changing to new variant - - errors.add :content, t(:core_cannot_change_content) if content_is_changing? - errors.add :type, t(:core_cannot_change_type) if type_is_changing? - detect_illegal_compound_names -end - -# STAGE: store - -event :expire_old_name, :store, changed: :name, on: :update do - Director.expirees << name_before_act -end - -event :rename_in_trash, after: :expire_old_name, on: :update do - existing_card = Card.find_by_key_and_trash name.key, true - return if !existing_card || existing_card == self - - existing_card.rename_as_trash_obstacle -end - -event :prepare_left_and_right, :store, changed: :name, on: :save do - return if name.simple? - - prepare_side :left - prepare_side :right -end - -event :update_lexicon, :finalize, changed: :name, on: :save do - lexicon_action = @action == :create ? :add : :update - Card::Lexicon.send lexicon_action, self -end - -event :cascade_name_changes, :finalize, on: :update, changed: :name do - each_descendant { |d| d.rename_as_descendant update_referers } -end - -protected - -def rename_as_trash_obstacle - self.name = "#{name}*trash" - rename_in_trash_without_callbacks - save! -end - -def rename_as_descendant referers=true - self.action = :update - referers ? update_referers : update_referer_references_out - refresh_references_in - refresh_references_out - expire - Card::Lexicon.update self -end - -private - -def name_incomplete? - name.parts.include?("") && !superleft&.autoname? -end - -def changed_from_simple_to_compound? - name.compound? && name_before_act.to_name.simple? -end - -def detect_illegal_compound_names - return unless changed_from_simple_to_compound? && child_ids(:right).present? - - errors.add :name, "illegal name change; existing names end in +#{name_before_act}" -end - -def changing_existing_tag_to_compound? - return false unless changing_name_to_compound? - - name_in_use_as_tag? -end - -def name_in_use_as_tag? - !Card.where(right_id: id, trash: false).take.nil? -end - -def changing_name_to_compound? - name.compound? && simple? -end - -def old_name_in_way? sidecard - real? && sidecard&.simple? && id == sidecard&.id -end - -def clear_name name - # move the current card out of the way, in case the new name will require - # re-creating a card with the current name, ie. A -> A+B - Card.where(id: id).update_all(name: nil, key: nil, left_id: nil, right_id: nil) - Card.expire name - Card::Lexicon.cache.reset # probably overkill, but this for an edge case... - # Card::Lexicon.delete id, key -end - -def prepare_side side - side_id = send "#{side}_id" - sidename = name.send "#{side}_name" - prepare_obstructed_side(side, side_id, sidename) || - prepare_new_side(side, side_id, sidename) -end - -def prepare_new_side side, side_id, sidename - return unless side_id == -1 || !Card[side_id]&.real? - - sidecard = Director.card(sidename) || add_subcard(sidename) - send "#{side}_id=", sidecard -end - -def prepare_obstructed_side side, side_id, sidename - return unless side_id && side_id == id - - clear_name sidename - send "#{side}_id=", add_subcard(sidename) - true -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/name_events.rb ~~ diff --git a/set/mod002-core/all/reference_events.rb b/set/mod002-core/all/reference_events.rb deleted file mode 100644 index 664aa75..0000000 --- a/set/mod002-core/all/reference_events.rb +++ /dev/null @@ -1,78 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (ReferenceEvents) -# -# test for updating referer content -module ReferenceEvents; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/reference_events.rb"; end -event :prepare_referer_update, :validate, on: :update, changed: :name do - self.update_referers = ![nil, false, "false"].member?(update_referers) -end - -# on rename, update names in cards that refer to self by name (as directed) -event :update_referer_content, :finalize, on: :update, when: :update_referers do - referers.each do |card| - next if card.structure - - card.skip_event! :validate_renaming, :check_permissions - card.content = card.replace_references name_before_act, name - attach_subcard card - end -end - -# on rename, when NOT updating referer content, update references to ensure -# that partial references are correctly tracked -# eg. A links to X+Y. if X+Y is renamed and we're not updating the link in A, -# then we need to be sure that A has a partial reference -event :update_referer_references_out, :finalize, - changed: :name, on: :update, when: :not_update_referers do - referers.map(&:update_references_out) -end - -# when name changes, update references to card -event :refresh_references_in, :finalize, changed: :name, on: :save do - Reference.unmap_referees id if action == :update && !update_referers - Reference.map_referees key, id -end - -# when content changes, update references to other cards -event :refresh_references_out, :finalize, on: :save, changed: :content do - update_references_out -end - -# clean up reference table when card is deleted -event :clear_references, :finalize, on: :delete do - delete_references_out - Reference.unmap_referees id -end - -# replace references in card content -def replace_references old_name, new_name - cont = content_object - cont.find_chunks(:Reference).each do |chunk| - next unless replace_reference chunk, old_name, new_name - end - cont.to_s -end - -protected - -def not_update_referers - !update_referers -end - -private - -def replace_reference chunk, old_name, new_name - return unless (old = chunk.referee_name) && (new = old.swap old_name, new_name) - - chunk.referee_name = chunk.replace_reference old_name, new_name - update_reference old.key, new.key -end - -def update_reference old_key, new_key - Reference.where(referee_key: old_key).update_all referee_key: new_key -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/reference_events.rb ~~ diff --git a/set/mod002-core/all/states.rb b/set/mod002-core/all/states.rb deleted file mode 100644 index f3f0174..0000000 --- a/set/mod002-core/all/states.rb +++ /dev/null @@ -1,93 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (States) -# -# All cards have one (and only one) of these three states: real, virtual, and unknown. -# -# - *real* cards are stored in the database (but not in the trash) and have a unique id. -# - *virtual* cards are not real, but they act real based on rules. For example, -# Home+*editors does a search for all the users who have edited the "Home" card. -# There are many other similar cards that search for things like references, children, -# etc. But we don't store all these cards in the database; we generate them dynamically -module States; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/states.rb"; end -# based on the names. -# - *unknown* cards are everything else. -# -# These states are frequently grouped as follows: -# -# - *known* cards are either _real_ or _virtual_ -# - *new* (or *unreal*) cards are either _unknown_ or _virtual_ - -module ClassMethods - def real? mark - quick_fetch(mark).present? - end - alias_method :exist?, :real? - alias_method :exists?, :real? - - def known? mark - fetch(mark).present? - end -end - -# @return [Symbol] :real, :virtual, or :unknown -def state anti_fishing=true - case - when !known? then :unknown - when anti_fishing && !ok?(:read) then :unknown - when real? then :real - when virtual? then :virtual - else :wtf - end -end - -# @return [True/False] -def real? - !unreal? -end - -# Virtual cards are structured, compound cards that are not stored in the database. You -# can create virtual cards with structure rules. -# -# Some cards with hard-coded content will also override the #virtual? method. This -# is established practice, but it is NOT advisable to override any of the other -# state methods. -# -# @return [True/False] -def virtual? - if @virtual.nil? - @virtual = real? || name.simple? ? false : structure.present? - end - @virtual -end - -# @return [True/False] -def unknown? - !known? -end - -# @return [True/False] -def known? - real? || virtual? -end - -# @return [True/False] -def new? - new_record? || # not yet in db (from ActiveRecord) - !@from_trash.nil? # in process of restoration from trash -end -alias_method :new_card?, :new? -alias_method :unreal?, :new? - -# has not been edited directly by human users. bleep blorp. -def pristine? - new_card? || !user_changes? -end - -def user_changes? - actions.joins(:act).where("card_acts.actor_id != ?", WagnBotID).exists? -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/states.rb ~~ diff --git a/set/mod002-core/all/subcards.rb b/set/mod002-core/all/subcards.rb deleted file mode 100644 index 45070aa..0000000 --- a/set/mod002-core/all/subcards.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Subcards) -# -module Subcards; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/subcards.rb"; end -event :reject_empty_subcards, :prepare_to_validate do - subcards.each_with_key do |subcard, key| - next unless subcard.new? && subcard.unfilled? - - remove_subcard(key) - director.subdirectors.delete(subcard) - end -end - -# check when deleting field that left has not also been deleted -def trashed_left? - l = left - !l || l.trash -end - -# check when renaming field that it is not actually the same field -# (eg on a renamed trunk) -def same_field? - (left_id == left_id_before_act) && (right_id == right_id_before_act) -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/subcards.rb ~~ diff --git a/set/mod002-core/all/trash.rb b/set/mod002-core/all/trash.rb deleted file mode 100644 index b2bc9d4..0000000 --- a/set/mod002-core/all/trash.rb +++ /dev/null @@ -1,142 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Trash) -# -module Trash; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/trash.rb"; end -Self::Admin.add_to_basket( - :tasks, - name: :empty_trash, - irreversible: true, - execute_policy: -> { Card.empty_trash }, - stats: { - title: "trashed cards", - count: -> { Card.where(trash: true) }, - link_text: "empty trash", - task: "empty_trash" - } -) - -module ClassMethods - def empty_trash - Card.delete_trashed_files - Card.where(trash: true).in_batches.update_all(left_id: nil, right_id: nil) - Card.where(trash: true).in_batches.delete_all - Card::Action.delete_cardless - Card::Change.delete_actionless - Card::Act.delete_actionless - Card::Reference.unmap_if_referee_missing - Card::Reference.delete_if_referer_missing - end - - # deletes any file not associated with a real card. - def delete_trashed_files - dir = Cardio.paths["files"].existent.first - # TODO: handle cloud files - return unless dir - - (all_trashed_card_ids & all_file_ids).each do |file_id| - delete_files_with_id dir, file_id - end - end - - def delete_files_with_id dir, file_id - raise Card::Error, t(:core_exception_almost_deleted) if Card.exists?(file_id) - - ::FileUtils.rm_rf "#{dir}/#{file_id}", secure: true - end - - def all_file_ids - dir = Card.paths["files"].existent.first - Dir.entries(dir)[2..-1].map(&:to_i) - end - - def all_trashed_card_ids - trashed_card_sql = %( select id from cards where trash is true ) - sql_results = Card.connection.select_all(trashed_card_sql) - sql_results.map(&:values).flatten.map(&:to_i) - end -end - -def trash? - trash -end - -def delete args={} - add_to_trash args do |delete_args| - update delete_args - end -end - -def delete! args={} - add_to_trash args do |delete_args| - update! delete_args - end -end - -def add_to_trash args - return if new_card? - - yield args.merge trash: true -end - -event :manage_trash, :prepare_to_store, on: :create do - pull_from_trash! - self.trash = false - true -end - -def pull_from_trash! - return unless (id = Card::Lexicon.id key) # name is already known - return unless (trashed_card = Card.where(id: id).take)&.trash - - # confirm name is actually in trash - - db_attributes["id"] = trashed_card.db_attributes["id"] - # id_in_database returns existing card id - - @from_trash = true - @new_record = false -end - -def db_attributes - send(:mutations_from_database).send :attributes -end - -event :validate_delete, :validate, on: :delete do - unless codename.blank? - errors.add :delete, t(:core_error_system_card, name: name, codename: codename) - end - - undeletable_all_rules_tags = - %w[default style layout create read update delete] - # FIXME: HACK! should be configured in the rule - - if compound? && left&.codename == :all && - undeletable_all_rules_tags.member?(right.codename.to_s) - errors.add :delete, t(:core_error_indestructible, name: name) - end - - errors.add :delete, t(:core_error_user_edits, name: name) if account && has_edits? -end - -event :validate_delete_children, after: :validate_delete, on: :delete do - return if errors.any? - - each_child do |child| - child.include_set_modules - delete_as_subcard child - # next if child.valid? - # child.errors.each do |field, message| - # errors.add field, "can't delete #{child.name}: #{message}" - # end - end -end - -def delete_as_subcard subcard - subcard.trash = true - add_subcard subcard -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/trash.rb ~~ diff --git a/set/mod002-core/all/type.rb b/set/mod002-core/all/type.rb deleted file mode 100644 index 8dd205d..0000000 --- a/set/mod002-core/all/type.rb +++ /dev/null @@ -1,70 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Type) -# -module Type; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/type.rb"; end -module ClassMethods - def default_type_id - @@default_type_id ||= Card[:all].fetch(:default, skip_modules: true).type_id - end -end - -def type_card - return if type_id.nil? - - Card.quick_fetch type_id.to_i -end - -def type_code - Card::Codename[type_id.to_i] -end - -def type_name - type_card.try :name -end - -alias_method :type, :type_name - -def type_name_or_default - type_card.try(:name) || Card.quick_fetch(Card.default_type_id).name -end - -def type_cardname - type_card.try :name -end - -def type= type_name - self.type_id = type_name.card_id -end - -def type_id= card_or_id - write_card_or_id :type_id, card_or_id -end - -def type_id_from_template - return unless name && (t = template) - - reset_patterns # still necessary even with new template handling? - self.type_id = t.type_id -end - -event :validate_type_change, :validate, on: :update, changed: :type_id do - return unless (c = dup) && c.action == :create && !c.valid? - - errors.add :type, t(:core_error_cant_change_errors, - name: name, - type_id: type_id, - error_messages: c.errors.full_messages) -end - -event :validate_type, :validate, changed: :type_id, on: :save do - errors.add :type, t(:core_error_no_such_type) unless type_name - - if (rt = structure) && rt.assigns_type? && type_id != rt.type_id - errors.add :type, t(:core_error_hard_templated, name: name, type_name: rt.type_name) - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/type.rb ~~ diff --git a/set/mod002-core/all/utils.rb b/set/mod002-core/all/utils.rb deleted file mode 100644 index 32e7bff..0000000 --- a/set/mod002-core/all/utils.rb +++ /dev/null @@ -1,104 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Utils) -# -module Utils; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/all/utils.rb"; end -module ClassMethods - def merge_list attribs, opts={} - unmerged = [] - attribs.each do |row| - if merge row["name"], row, opts - Rails.logger.info "merged #{row['name']}" - else - unmerged.push row - end - end - - if unmerged.empty? - Rails.logger.info "successfully merged all!" - else - unmerged_json = JSON.pretty_generate unmerged - report_unmerged_json unmerged_json, opts[:output_file] - end - unmerged - end - - def report_unmerged_json unmerged_json, output_file - if output_file - ::File.open output_file, "w" do |f| - f.write unmerged_json - end - else - Rails.logger.info "failed to merge:\n\n#{unmerged_json}" - end - end - - def merge name, attribs={}, opts={} - # puts "merging #{name}" - card = fetch name, new: {} - return unless mergeable? card, opts[:pristine] - - resolve_file_attributes! attribs - card.safe_update! attribs - end - - private - - def resolve_file_attributes! attribs - %i[image file].each do |attach| - next unless attribs[attach].is_a?(String) - - attribs[attach] = ::File.open(attribs[attach]) - end - end - - def mergeable? card, pristine_only - return true unless pristine_only - - !card.pristine? - end -end - -# separate name and other attributes -def safe_update! attribs - separate_name_update! attribs.delete("name") unless new? - update! attribs if attribs.present? -end - -def separate_name_update! new_name - return if new_name.to_s == name.to_s - - update! name: new_name -end - -# rubocop:disable Style/GlobalVars -def measure desc - $times ||= {} - res = nil - t = Benchmark.measure do - res = yield - end - $times[desc] = $times.key?(desc) ? t + $times[desc] : t - puts "#{desc}: #{t}".red - res -end -# rubocop:enable Style/GlobalVars - -def mod_root modname - if (spec = Gem::Specification.find_by_name "card-mod-#{modname}") - spec.full_gem_path - else - "#{Cardio.gem_root}/mod/#{modname}" - end -end - -delegate :t, to: Cardio - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - delegate :t, to: Cardio - delegate :measure, to: :card -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/all/utils.rb ~~ diff --git a/set/mod002-core/right/autoname.rb b/set/mod002-core/right/autoname.rb deleted file mode 100644 index f61a2a9..0000000 --- a/set/mod002-core/right/autoname.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Autoname" cards -# -module Autoname; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/right/autoname.rb"; end -def history? - false -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/right/autoname.rb ~~ diff --git a/set/mod002-core/self/autoname.rb b/set/mod002-core/self/autoname.rb deleted file mode 100644 index 2693a81..0000000 --- a/set/mod002-core/self/autoname.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Autoname" -# -module Autoname; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/self/autoname.rb"; end -setting_opts group: :templating, position: 4, - help_text: "Autogenerate name for new cards by incrementing this value. "\ - "[[http://decko.org/autonaming|more]]" -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/self/autoname.rb ~~ diff --git a/set/mod002-core/self/trash.rb b/set/mod002-core/self/trash.rb deleted file mode 100644 index b1f43ea..0000000 --- a/set/mod002-core/self/trash.rb +++ /dev/null @@ -1,73 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Trash" -# -module Trash; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/self/trash.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core do - rows = trashed_cards.map { |tc| trash_table_row(tc) } - output [ - restored, - (empty_trash_link if rows.present?), - table(rows, header: ["card", "deleted", "by", ""]) - ] - end - - def trashed_cards - Card.where(trash: true).order(updated_at: :desc) - end - - def trash_table_row card - [ - card.name, - "#{time_ago_in_words(card.updated_at)} ago", - Card[card.updater_id].name, - "#{history_link(card)} | #{restore_link(card)}" - ] - end - - def restored - return unless (res_id = Env.params[:restore]) && - (res_card = Card[res_id.to_i]) - - alert :success, true do - wrap_with(:h5, "restored") + subformat(res_card).render_bar - end - end - - def empty_trash_link - wrap_with( - :p, - button_link("empty trash", - btn_type: :default, - path: { mark: :admin, action: :update, task: :empty_trash, - success: { mark: "~#{card.id}" } }, - "data-confirm" => "Are you sure you want to delete "\ - "all cards in the trash?") - ) - end - - def history_link trashed_card - link_to_card trashed_card, "history", - path: { view: :history, look_in_trash: true } - end - - def restore_link trashed_card - before_delete = trashed_card.actions[-2] - link_to "restore", method: :post, - rel: "nofollow", - remote: true, - class: "slotter", - path: { id: trashed_card.id, - view: :open, - look_in_trash: true, - action: :update, - restore: trashed_card.id, - action_ids: [before_delete], - success: { mark: "~#{card.id}" } } - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/self/trash.rb ~~ diff --git a/set/mod002-core/self/version.rb b/set/mod002-core/self/version.rb deleted file mode 100644 index 9a12698..0000000 --- a/set/mod002-core/self/version.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Version" -# -# -*- encoding : utf-8 -*- -module Version; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/self/version.rb"; end - -def ok_to_read - true -end - -def content - Card::Version.release -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/self/version.rb ~~ diff --git a/set/mod002-core/type/cardtype.rb b/set/mod002-core/type/cardtype.rb deleted file mode 100644 index 3b17f72..0000000 --- a/set/mod002-core/type/cardtype.rb +++ /dev/null @@ -1,37 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Cardtype" cards -# -module Cardtype; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/card/mod/core/set/type/cardtype.rb"; end -def cards_of_type_exist? - !new_card? && Card.where(trash: false, type_id: id).exists? -end - -def create_ok? - Card.new(type_id: id).ok? :create -end - -def was_cardtype? - type_id_before_act == Card::CardtypeID -end - -event :check_for_cards_of_type, after: :validate_delete do - errors.add :cardtype, t(:core_cards_exist, cardname: name) if cards_of_type_exist? -end - -event :check_for_cards_of_type_when_type_changed, - :validate, changing: :type, when: :was_cardtype? do - if cards_of_type_exist? - errors.add :cardtype, t(:core_error_cant_alter, name: name_before_act) - end -end - -event :validate_cardtype_name, :validate, on: :save, changed: :name do - if %r{[<>/]}.match?(name) - errors.add :name, t(:core_error_invalid_character_in_cardtype, banned: "<, >, /") - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/card/mod/core/set/type/cardtype.rb ~~ diff --git a/set/mod004-email/abstract/email_field.rb b/set/mod004-email/abstract/email_field.rb deleted file mode 100644 index 45d7899..0000000 --- a/set/mod004-email/abstract/email_field.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (EmailField) -# -module EmailField; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/abstract/email_field.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - # turn off autodetection of uri's - def chunk_list - :references - end -end - -# format :html do -# def pointer_items args -# card.item_names(context: :raw).map do |iname| -# wrap_item iname, args -# end -# end -# end# - -module EmailTextFormat; module_parent.send :register_set_format, Card::Format::EmailTextFormat, self; extend Card::Set::AbstractFormat - def email_addresses context - context ||= self - card.item_names(context: context.name).map do |name| - # FIXME: context is processed twice here because pointers absolutize - # item_names by default while other types can return relative names. - # That's poor default behavior and should be fixed! - name = name.to_name.absolute context - email_address?(name) ? name : email_address_from_card(name, context) - end.flatten.compact.join(", ") - end - - def email_address? string - string =~ /.+@.+\..+/ - end - - def email_address_from_card name, context - card = Card.fetch name - card.account&.email || email_addresses_from_card_content(card, context) - end - - def email_addresses_from_card_content card, context - subformat(card).contextual_content(context).split(/[,\n]/) - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/abstract/email_field.rb ~~ diff --git a/set/mod004-email/abstract/test_context.rb b/set/mod004-email/abstract/test_context.rb deleted file mode 100644 index 181581a..0000000 --- a/set/mod004-email/abstract/test_context.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (TestContext) -# -module TestContext; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/abstract/test_context.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core do - return super() if voo.hide? :test_context - - card.with_context test_context_card do - super() - end - end - - def test_context_card - card.left.fetch(:test_context)&.item_card - end -end - -module EmailHtmlFormat; module_parent.send :register_set_format, Card::Format::EmailHtmlFormat, self; extend Card::Set::AbstractFormat - view :core do - voo.hide! :test_context - super() - end -end - -module EmailTextFormat; module_parent.send :register_set_format, Card::Format::EmailTextFormat, self; extend Card::Set::AbstractFormat - view :core do - voo.hide! :test_context - super() - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/abstract/test_context.rb ~~ diff --git a/set/mod004-email/all/email_html.rb b/set/mod004-email/all/email_html.rb deleted file mode 100644 index f340b34..0000000 --- a/set/mod004-email/all/email_html.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (EmailHtml) -# -module EmailHtml; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/all/email_html.rb"; end -module EmailHtmlFormat; module_parent.send :register_set_format, Card::Format::EmailHtmlFormat, self; extend Card::Set::AbstractFormat - view :unknown do - "" - end - - view :compact_missing do - "" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/all/email_html.rb ~~ diff --git a/set/mod004-email/all/email_text.rb b/set/mod004-email/all/email_text.rb deleted file mode 100644 index c7df4fc..0000000 --- a/set/mod004-email/all/email_text.rb +++ /dev/null @@ -1,22 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (EmailText) -# -module EmailText; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/all/email_text.rb"; end -module EmailTextFormat; module_parent.send :register_set_format, Card::Format::EmailTextFormat, self; extend Card::Set::AbstractFormat - view :unknown do - "" - end - - view :compact_missing do - "" - end - - view :last_action, perms: :none, cache: :never do - _render_last_action_verb - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/all/email_text.rb ~~ diff --git a/set/mod004-email/right/bcc.rb b/set/mod004-email/right/bcc.rb deleted file mode 100644 index 20546b5..0000000 --- a/set/mod004-email/right/bcc.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Bcc" cards -# -module Bcc; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/right/bcc.rb"; end -include_set Abstract::EmailField -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/right/bcc.rb ~~ diff --git a/set/mod004-email/right/cc.rb b/set/mod004-email/right/cc.rb deleted file mode 100644 index e9437e0..0000000 --- a/set/mod004-email/right/cc.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Cc" cards -# -module Cc; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/right/cc.rb"; end -include_set Abstract::EmailField -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/right/cc.rb ~~ diff --git a/set/mod004-email/right/from.rb b/set/mod004-email/right/from.rb deleted file mode 100644 index b722af2..0000000 --- a/set/mod004-email/right/from.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+From" cards -# -module From; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/right/from.rb"; end -include_set Abstract::EmailField -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/right/from.rb ~~ diff --git a/set/mod004-email/right/html_message.rb b/set/mod004-email/right/html_message.rb deleted file mode 100644 index 9fdd26a..0000000 --- a/set/mod004-email/right/html_message.rb +++ /dev/null @@ -1,23 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+HtmlMessage" cards -# -module HtmlMessage; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/right/html_message.rb"; end -include_set Abstract::TestContext - -def clean_html? - false -end - -module EmailHtmlFormat; module_parent.send :register_set_format, Card::Format::EmailHtmlFormat, self; extend Card::Set::AbstractFormat - def email_content context - content = contextual_content context - return unless content.present? - - Card::Mailer.layout content - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/right/html_message.rb ~~ diff --git a/set/mod004-email/right/subject.rb b/set/mod004-email/right/subject.rb deleted file mode 100644 index f92cfdc..0000000 --- a/set/mod004-email/right/subject.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Subject" cards -# -module Subject; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/right/subject.rb"; end -include_set Abstract::TestContext -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/right/subject.rb ~~ diff --git a/set/mod004-email/right/text_message.rb b/set/mod004-email/right/text_message.rb deleted file mode 100644 index 70a4ee7..0000000 --- a/set/mod004-email/right/text_message.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+TextMessage" cards -# -module TextMessage; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/right/text_message.rb"; end -include_set Abstract::TestContext -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/right/text_message.rb ~~ diff --git a/set/mod004-email/right/to.rb b/set/mod004-email/right/to.rb deleted file mode 100644 index 39a4916..0000000 --- a/set/mod004-email/right/to.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+To" cards -# -module To; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/right/to.rb"; end -include_set Abstract::EmailField -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/right/to.rb ~~ diff --git a/set/mod004-email/type/email_template.rb b/set/mod004-email/type/email_template.rb deleted file mode 100644 index 16231b3..0000000 --- a/set/mod004-email/type/email_template.rb +++ /dev/null @@ -1,101 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "EmailTemplate" cards -# -module EmailTemplate; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/type/email_template.rb"; end -def clean_html? - false -end - -def deliver context=nil, fields={}, opts={} - mail = format.mail context, fields, opts - mail.deliver -rescue Net::SMTPError => e - errors.add :exception, e.message -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def mail context=nil, fields={}, opts={} - config = card.email_config context, fields, opts - fmt = self # self is within the new_mail block - Card::Mailer.new_mail config do - fmt.message_body self, config - fmt.add_attachments self, config.delete(:attach) - end - end - - def message_body mail, config - config[:html_message] &&= config[:html_message].call mail - method, args = body_method_and_args config[:html_message].present?, - config[:text_message].present? - args = Array.wrap(args).map { |arg| config[arg] } - send method, mail, *args - end - - def body_method_and_args html, text - if html && text - [:text_and_html_message, %i[text_message html_message attach]] - elsif html - %i[html_body html_message] - else - %i[text_body text_message] - end - end - - def text_and_html_message mail, text_message, html_message, attachment_list=nil - fmt = self - if attachment_list&.any? - mail.multipart_mixed text_message, html_message - else - mail.text_part { body text_message } - mail.html_part { fmt.html_body self, html_message } - end - end - - def multipart_mixed mail, text_message, html_message - mail.content_type "multipart/mixed" - mail.part content_type: "multipart/alternative" do |copy| - copy.part content_type: "text/plain" do |plain| - plain.body = text_message - end - copy.part content_type: "text/html" do |html| - html.body = html_message - end - end - end - - def html_body mail, message - mail.content_type "text/html; charset=UTF-8" - mail.body message - end - - def text_body mail, message - mail.content_type "text/plain; charset=UTF-8" - mail.text_part { body message } - end - - def add_attachments mail, list - return unless list.present? - - each_valid_attachment list do |file, index| - mail.add_file filename: attachment_name(file, index), - content: File.read(file.path) - end - end - - def each_valid_attachment list - list.each_with_index do |cardname, index| - next unless (file = Card[cardname]&.try(:attachment)) - - yield file, index - end - end - - def attachment_name file, number - "attachment-#{number + 1}.#{file.extension}" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/type/email_template.rb ~~ diff --git a/set/mod004-email/type/email_template/email_config.rb b/set/mod004-email/type/email_template/email_config.rb deleted file mode 100644 index c40e700..0000000 --- a/set/mod004-email/type/email_template/email_config.rb +++ /dev/null @@ -1,92 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type; module EmailTemplate; -# Set: All "EmailTemplate+EmailConfig" cards (EmailConfig) -# -module EmailConfig; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/email/set/type/email_template/email_config.rb"; end -EMAIL_FIELDS = - %i[to from cc bcc attach subject text_message html_message].freeze - -EMAIL_FIELD_METHODS = - { subject: :contextual_content, - text_message: :contextual_content, - attach: :extended_item_contents }.freeze - -# @param [Card] context the card in whose context all email fields will be interpreted -# @param [Hash] fields override any templated field configurations with hash values -# @param [Hash] opts options for rendering. unknown options become format options -# @option opts [Card, String, Integer] :auth user identifier. render as this user -def email_config context, fields={}, opts={} - @active_email_context = context || self - auth = opts.delete :auth - config = EMAIL_FIELDS.each_with_object({}) do |field, conf| - conf[field] = fields[field] || email_field_from_card(field, auth, opts) - end - safe_from_and_reply_to! config - config.select { |_k, v| v.present? } -end - -def email_field_from_card field, auth, format_opts - return unless (field_card = fetch(field)) - - auth ||= field_card.updater - special_email_field_method(field, field_card, auth, format_opts) || - standard_email_field(field, field_card, auth, format_opts) -end - -def special_email_field_method field, field_card, auth, format_opts - method = "email_#{field}_field" - return unless respond_to? method - - send method, field_card, auth, format_opts -end - -def standard_email_field field, field_card, auth, format_opts - method = EMAIL_FIELD_METHODS[field] || :email_addresses - format_opts = format_opts.merge format: :email_text - Auth.as auth do - field_card.format(format_opts).send method, @active_email_context - end -end - -# html messages return procs because image attachments can't be properly rendered -# without a mail object. (which isn't available at initial config time) -def email_html_message_field message_card, auth, format_opts - proc do |mail| - Auth.as auth do - format_opts = format_opts.merge format: :email_html, active_mail: mail - message_card.format(format_opts).email_content @active_email_context - end - end -end - -# whenever a default "from" field is configured in Card::Mailer, emails are always -# actually "from" that address -def safe_from_and_reply_to! config - conf_name, conf_email = configured_from_name_and_email config[:from] - actual_email = Card::Mailer.default[:from] || conf_email - config[:from] = email_from_field_value conf_name, conf_email, actual_email - config[:reply_to] ||= actual_email -end - -def email_from_field_value conf_name, conf_email, actual_email - conf_text = conf_name || conf_email - if conf_text != actual_email - %("#{conf_text}" <#{actual_email}>) - elsif actual_email.present? - actual_email - else - Card[WagnBotID].account.email - end -end - -def configured_from_name_and_email raw_string - if raw_string =~ /(.*)<(.*)>/ - [Regexp.last_match(1).strip, Regexp.last_match(2)] - else - [nil, raw_string] - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/email/set/type/email_template/email_config.rb ~~ diff --git a/set/mod005-collection/abstract/items.rb b/set/mod005-collection/abstract/items.rb deleted file mode 100644 index c26ba4a..0000000 --- a/set/mod005-collection/abstract/items.rb +++ /dev/null @@ -1,215 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Items) -# -# ~~~~~~~~~~~~ READING ITEMS ~~~~~~~~~~~~ - -module Items; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/items.rb"; end -# While each of the three main methods for returning lists of items can handle arguments, -# they are most commonly used without them. - -# @return [Array] list of Card::Name objects -# @param args [Hash] -# @option args [String] :content override card content -# @option args [String, Card::Name, Symbol] :context name in whose context relative items -# will be interpreted. For example. +A in context of B is interpreted as B+A -# context defaults to pointer card's name. If value is `:raw`, then name is not -# contextualized -# @option args [String, Integer] :limit max number of cards to return -# @option args [String, Integer] :offset begin after the offset-th item -def item_names args={} - context = args[:context] - item_strings(args).map do |item| - clean_item_name item, context - end.compact -end - -def first_name args={} - item_names(args).first -end - -def first_card args={} - return unless (name = first_name) - - fetch_item_card name, args -end - -def first_code - first_card&.codename -end - -def first_id - first_card&.id -end - -# @return [Array] list of integers (card ids of items) -# @param args [Hash] see #item_names -def item_ids args={} - item_names(args).map(&:card_id).compact -end - -# @return [Array] list of Card objects -# @param args [Hash] see #item_names for additional options -# @option args [String] :complete keyword to use in searching among items -# @option args [True/False] :known_only if true, return only known cards -# @option args [String] :type name of type to be used for unknown cards -def item_cards args={} - return item_cards_search(args) if args[:complete] - return known_item_cards(args) if args[:known_only] - - all_item_cards args -end - -# #item_name, #item_id, and #item_card each return a single item, rather than an array. -%i[name id card].each do |obj| - define_method "item_#{obj}" do |args={}| - send("item_#{obj}s", args.merge(limit: 1)).first - end -end - -# for override, eg by json -def item_value item_name - item_name -end - -# ~~~~~~~~~~~~ ALTERING ITEMS ~~~~~~~~~~~~ - -# set card content based on array and save card -# @param array [Array] list of strings/names (Cardish) -def items= array - items_to_content array - save! -end - -# append item to list (does not save) -# @param cardish [Cardish] -def << cardish - add_item cardish -end - -# append item to list (does not save) -# @param cardish [String, Card::Name] item name -# @param allow_duplicates [True/False] permit duplicate items (default is False) -def add_item cardish, allow_duplicates=false - return if !allow_duplicates && include_item?(cardish) - - items = item_strings << cardish - items_to_content items -end - -# append item to list and save card -# @param name [String, Card::Name] item name -def add_item! name - add_item(name) && save! -end - -# remove item from list -# @param cardish [String, Card::Name] item to drop -def drop_item cardish - drop_item_name = Card::Name[cardish] - items_to_content(item_names.reject { |item_name| item_name == drop_item_name }) -end - -# remove item from list and save card -# @param cardish [String, Card::Name] item to drop -def drop_item! cardish - drop_item cardish - save! -end - -# insert item into list at specified location -# @param index [Integer] Array index in which to insert item (0 is first) -# @param name [String, Card::Name] item name -def insert_item index, name - new_names = item_names - new_names.delete name - new_names.insert index, name - items_to_content new_names -end - -# insert item into list at specified location and save -# @param index [Integer] Array index in which to insert item (0 is first) -# @param name [String, Card::Name] item name -def insert_item! index, name - insert_item index, name - save! -end - -# ~~~~~~~~~~~~ READING ITEM HELPERS ~~~~~~~~~~~~ - -# Warning: the following methods, while available for use, may be subject to change - -# #item_cards helpers - -def item_cards_search query - Card::Query.run query.reverse_merge(referred_to_by: name, limit: 0) -end - -def known_item_cards args={} - item_names(args).map { |name| Card.fetch name }.compact -end - -def all_item_cards args={} - names = args[:item_names] || item_names(args) - names.map { |name| fetch_item_card name, args } -end - -# TODO: support type_code and type_id. (currently type) -# uses name, because its most common use is from CQL -def item_type - opt = options_rule_card - # FIXME: need better recursion prevention - return if !opt || opt == self - - opt.item_type -end - -def item_strings args={} - items = raw_item_strings(args[:content] || content) - return items unless args.present? - - filtered_items items, limit: args[:limit], offset: args[:offset] -end - -def raw_item_strings content - content.to_s.split(/\n+/).map { |i| strip_item i } -end - -private - -def filtered_items items, limit: 0, offset: 0 - limit = limit.to_i - offset = offset.to_i - return items unless limit.positive? || offset.positive? - - items[offset, (limit.zero? ? items.size : limit)] || [] -end - -def fetch_item_card name, args={} - Card.fetch name, new: new_unknown_item_args(args) -end - -def new_unknown_item_args args - itype = args[:type] || item_type - itype ? { type: itype } : {} -end - -def clean_item_name item, context - item = item.to_name - return item if context == :raw - - context ||= context_card.name - item.absolute_name context -rescue Card::Error::NotFound - # eg for invalid ids or codenames - # "Invalid Item: #{item}".to_name - nil -end - -def strip_item item - item.gsub(/\[\[|\]\]/, "").strip -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/items.rb ~~ diff --git a/set/mod005-collection/abstract/paging.rb b/set/mod005-collection/abstract/paging.rb deleted file mode 100644 index 7e787c4..0000000 --- a/set/mod005-collection/abstract/paging.rb +++ /dev/null @@ -1,74 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Paging) -# -module Paging; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/paging.rb"; end -MAX_ANONYMOUS_SEARCH_PARAM = 1000 - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def limit - @limit ||= contextual_param(:limit) || default_limit - end - - def offset - @offset ||= contextual_param(:offset) || 0 - end - - def search_with_params - @search_with_params ||= card.item_names - end - - def count_with_params - @count_with_params ||= card.item_names.count - end - - def total_pages - return 1 if limit.zero? - - ((count_with_params - 1) / limit).to_i - end - - def current_page - (offset / limit).to_i - end - - # for override - def extra_paging_path_args - {} - end - - private - - def contextual_param param - env_search_param(param) || voo_search_param(param) - end - - def env_search_param param - enforcing_legal_limit param do - val = Env.params[param] - val.to_i if focal? && val.present? - end - end - - def enforcing_legal_limit param - yield.tap do |val| - enforce_legal_limit! val if param == :limit - end - end - - def enforce_legal_limit! val - return if Card::Auth.signed_in? || !val || val <= MAX_ANONYMOUS_SEARCH_PARAM - - raise Card::Error::PermissionDenied, - "limit parameter exceeds maximum for anonymous users " \ - "(#{MAX_ANONYMOUS_SEARCH_PARAM})" - end - - def voo_search_param param - voo&.cql&.dig(param)&.to_i - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/paging.rb ~~ diff --git a/set/mod005-collection/abstract/paging/paging_links.rb b/set/mod005-collection/abstract/paging/paging_links.rb deleted file mode 100644 index 99b7b70..0000000 --- a/set/mod005-collection/abstract/paging/paging_links.rb +++ /dev/null @@ -1,99 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Paging) -# -#! no set module - -module Paging; -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/paging/paging_links.rb"; end -# render paging links -class PagingLinks - def initialize total_pages, current_page - @total = total_pages - @current = current_page - end - - # @param window [integer] number of page links shown left and right - # of the current page - # @example: current page = 5, window = 2 - # |<<|1|...|3|4|[5]|6|7|...|10|>>| - # @yield [text, page, status, options] block to build single paging link - # @yieldparam status [Symbol] :active (for current page) or :disabled - # @yieldparam page [Integer] page number, first page is 0 - # @return [Array] - def build window=2, &block - @render_item = block - links window - end - - private - - def links window - @window_start = [@current - window, 0].max - @window_end = [@current + window, @total].min - left_part + window_part + right_part - end - - # the links around the current page - def window_part - (@window_start..@window_end).map do |page| - direct_page_link page - end.compact - end - - def left_part - [ - previous_page_link, - (direct_page_link 0 if @window_start.positive?), - (ellipse if @window_start > 1) - ].compact - end - - def right_part - [ - (ellipse if @total > @window_end + 1), - (direct_page_link @total if @total > @window_end), - next_page_link - ].compact - end - - def previous_page_link - paging_item '', previous_page, - "aria-label" => "Previous", status: :previous - end - - def next_page_link - paging_item '', next_page, - "aria-label" => "Next", status: :next - end - - def direct_page_link page - return unless page >= 0 && page <= @total - - paging_item page + 1, page - end - - def ellipse - paging_item "...", nil, status: :ellipses - end - - def paging_item text, page, options={} - status = - if page == @current - :current - else - options.delete :status - end - @render_item.call text, page, status, options - end - - def previous_page - @current.positive? ? @current - 1 : false - end - - def next_page - @current < @total ? @current + 1 : false - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/paging/paging_links.rb ~~ diff --git a/set/mod005-collection/abstract/paging/paging_views.rb b/set/mod005-collection/abstract/paging/paging_views.rb deleted file mode 100644 index 96c2cad..0000000 --- a/set/mod005-collection/abstract/paging/paging_views.rb +++ /dev/null @@ -1,121 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract; module Paging; -# Set: Abstract (Paging, PagingViews) -# -module PagingViews; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/paging/paging_views.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - PAGE_LI_CLASS = { ellipses: "disabled", current: "active" }.freeze - - def with_paging path_args={} - with_paging_path_args path_args do - output [yield(@paging_path_args), _render_paging] - end - end - - view :paging, cache: :never do - return "" unless paging_needed? - - <<-HTML - - HTML - end - - def paging_links - PagingLinks.new(total_pages, current_page).build do |text, page, status, options| - page_link_li text, page, status, options - end - end - - # First page is 0 (not 1) - def page_link_li text, page, status, options={} - wrap_with :li, class: page_link_li_class(status) do - page_link text, page, options - end - end - - def page_link_li_class status - ["page-item", PAGE_LI_CLASS[status]].compact.join " " - end - - def page_link text, page, options - return content_tag(:div, text.html_safe, class: "page-link") unless page - - options.merge! class: "card-paging-link slotter page-link", - remote: true, - path: page_link_path_args(page) - link_to raw(text), options - end - - def with_paging_path_args args - tmp = @paging_path_args - @paging_path_args = paging_path_args args - yield - ensure - @paging_path_args = tmp - end - - def paging_path_args local_args={} - @paging_path_args ||= {} - @paging_path_args.reverse_merge!(limit: limit, offset: offset) - @paging_path_args.merge! extra_paging_path_args - @paging_path_args.merge local_args - end - - def page_link_path_args page - paging_path_args.merge offset: page * limit - end - - def paging_needed? - return false if limit < 1 - return false if fewer_results_than_limit? # avoid extra count search - - # count search result instead - limit < count_with_params - end - - # clear we don't need paging even before running count query - def fewer_results_than_limit? - return false unless offset.zero? - - limit > offset + search_with_params.length - end -end - -module JsonFormat; module_parent.send :register_set_format, Card::Format::JsonFormat, self; extend Card::Set::AbstractFormat - def page_link_path_args page - { - limit: limit, - offset: page * limit, - item: default_item_view, # hack. need standard voo handling - format: :json - }.merge extra_paging_path_args - end - - view :paging_urls, cache: :never do - return {} unless total_pages > 1 - - { paging: paging_urls_hash } - end - - def paging_urls_hash - hash = {} - PagingLinks.new(total_pages, current_page).build do |_text, page, status, _options| - add_paging_url hash, page, status - end - hash - end - - def add_paging_url hash, page, status - return unless page && status.in?(%i[next previous]) - - hash[status] = path page_link_path_args(page) - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/collection/set/abstract/paging/paging_views.rb ~~ diff --git a/set/mod005-collection/all/extended.rb b/set/mod005-collection/all/extended.rb deleted file mode 100644 index fed199b..0000000 --- a/set/mod005-collection/all/extended.rb +++ /dev/null @@ -1,59 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Extended) -# -module Extended; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/collection/set/all/extended.rb"; end -def extended_item_cards context=nil - items = item_cards limit: "", context: (context || self).name - list = [] - book = ::Set.new # avoid loops - extend_item_list items, list, book until items.empty? - list -end - -def extended_item_contents context=nil - extended_item_cards(context).map(&:item_names).flatten -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - delegate :extended_item_contents, to: :card -end - -private - -def extend_item_list items, list, book - item = items.shift - return if already_extended? item, book - - if item.collection? - # keep items in order - items.unshift(*item.item_cards) - else # no further level of items - list << item - end -end - -def already_extended? item, book - return true if book.include? item - - book << item - false -end - -# def extended_list context=nil -# context = (context ? context.name : name) -# args = { limit: "" } -# item_cards(args.merge(context: context)).map do |x| -# x.item_cards(args) -# end.flatten.map do |x| -# x.item_cards(args) -# end.flatten.map do |y| -# y.item_names(args) -# end.flatten -# # this could go on and on. more elegant to recurse until you don't have -# # a collection -# end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/collection/set/all/extended.rb ~~ diff --git a/set/mod005-collection/all/item.rb b/set/mod005-collection/all/item.rb deleted file mode 100644 index d204f96..0000000 --- a/set/mod005-collection/all/item.rb +++ /dev/null @@ -1,145 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Item) -# -module Item; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/collection/set/all/item.rb"; end -def item_names _args={} - format._render_raw.split(/[,\n]/) -end - -# FIXME: this is inconsistent with item_names -def item_cards _args={} - [self] -end - -def item_type - nil -end - -def item_keys args={} - item_names(args).map do |item| - item.to_name.key - end -end - -def item_count args={} - item_names(args).size -end - -def items_to_content array - items = array.map { |i| standardize_item i }.reject(&:blank?) - self.content = items.to_pointer_content -end - -def standardize_item item - Card::Name[item] -end - -def include_item? item - item_names.include? Card::Name[item] -end - -def add_item item - return if include_item? item - - items_to_content(items_strings << item) -end - -def drop_item item - item = Card::Name[item] - return unless include_item? item - - items_to_content(item_names.reject { |i| i == item }) -end - -def insert_item index, name - new_names = item_names - new_names.delete name - new_names.insert index, name - items_to_content new_names -end - -def replace_item old, new - return unless include_item? old - - drop_item old - add_item new -end - -# I think the following should work as add_item... -# -def add_id id - add_item "~#{id}" -end - -def drop_id id - drop_item "~#{id}" -end - -def insert_id index, id - insert_item index, "~#{id}" -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def item_links _args={} - raw(render_core).split(/[,\n]/) - end - - def nest_item cardish, options={}, &block - options = item_view_options options - options[:nest_name] = Card::Name[cardish].s - nest cardish, options, &block - end - - def implicit_item_view - view = voo_items_view || default_item_view - Card::View.normalize view - end - - def voo_items_view - return unless voo && (items = voo.items) - - items[:view] - end - - def default_item_view - :name - end - - def item_view_options new_options={} - options = (voo.items || {}).clone - options = options.merge new_options - options[:view] ||= implicit_item_view - determine_item_view_options_type options - options - end - - def determine_item_view_options_type options - return if options[:type] - - type_from_rule = card.item_type - options[:type] = type_from_rule if type_from_rule - end - - def listing listing_cards, item_args={} - listing_cards.map do |item_card| - nest_item item_card, item_args do |rendered, item_view| - wrap_item rendered, item_view - end - end - end - - def wrap_item item, _args={} - item # no wrap in base - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def wrap_item rendered, item_view - %(
#{rendered}
) - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/collection/set/all/item.rb ~~ diff --git a/set/mod006-content/abstract/00_sources.rb b/set/mod006-content/abstract/00_sources.rb deleted file mode 100644 index 9354e7f..0000000 --- a/set/mod006-content/abstract/00_sources.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Sources) -# -module Sources; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/00_sources.rb"; end -def source_paths - [] -end - -def find_file file_path - unknown_file?(file_path) ? nil : file_path -end - -def unknown_file? file_path - return false if File.exist? file_path - - Rails.logger.info "couldn't locate file #{file_path}" - true -end - -def existing_source_paths - Array.wrap(source_paths).reject do |file_path| - unknown_file?(file_path) - end.compact -end - -def source_changed? since: - existing_source_paths.any? { |path| ::File.mtime(path) > since } -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/00_sources.rb ~~ diff --git a/set/mod006-content/abstract/01_code_file.rb b/set/mod006-content/abstract/01_code_file.rb deleted file mode 100644 index 6ff33e0..0000000 --- a/set/mod006-content/abstract/01_code_file.rb +++ /dev/null @@ -1,94 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (CodeFile) -# -module CodeFile; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/01_code_file.rb"; end -include_set Abstract::Sources - -class << self - - def included host_class - track_mod_name host_class, caller - end - - def track_mod_name host_class, caller - host_class.mattr_accessor :file_content_mod_name - host_class.file_content_mod_name = Card::Set.mod_name(caller) - end -end - -# FIXME: these should abstracted and configured on the types -# (same codes for `rake card:create:codefile`) - -# @return [Array, String] the name of file(s) to be loaded -def source_files - case type_id - when CoffeeScriptID then "#{codename}.js.coffee" - when JavaScriptID then "#{codename}.js" - when CssID then "#{codename}.css" - when ScssID then "#{codename}.scss" - end -end - -def source_dir - case type_id - when CoffeeScriptID, JavaScriptID then "lib/javascript" - when CssID, ScssID then "lib/stylesheets" - else - "lib" - end -end - -def mod_path - modname = file_content_mod_name - if (match = modname.match(/^card-mod-(\w*)/)) - modname = match[1] - end - Cardio::Mod.dirs.path modname -end - -def source_paths - Array.wrap(source_files).map do |filename| - ::File.join mod_path, source_dir, filename - end -end - -def content - Array.wrap(source_files).map do |filename| - if (source_path = find_file filename) - Rails.logger.debug "reading file: #{source_path}" - ::File.read source_path - end - end.compact.join "\n" -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :input do - "Content is stored in file and can't be edited." - end - - view :file_size do - "#{card.name}: #{number_to_human_size card.content.bytesize}" - end - - def short_content - fa_icon("exclamation-circle", class: "text-muted pr-2") + - wrap_with(:span, "file", class: "text-muted") - end - - def standard_submit_button - multi_card_editor? ? super : "" - end -end - -def coffee_files files - files.map { |f| "script_#{f}.js.coffee" } -end - -def scss_files files - files.map { |f| "style_#{f}.scss" } -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/01_code_file.rb ~~ diff --git a/set/mod006-content/abstract/asset_file.rb b/set/mod006-content/abstract/asset_file.rb deleted file mode 100644 index 8ff95b6..0000000 --- a/set/mod006-content/abstract/asset_file.rb +++ /dev/null @@ -1,84 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (AssetFile) -# -module AssetFile; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/asset_file.rb"; end -include_set Abstract::CodeFile - -def source_path - db_content -end - -def source_files - db_content -end - -def find_file path - path.tap do |file_path| - return nil if unknown_file? file_path - end -end - -def unknown_file? file_path - return false if ::File.exist? file_path - - Rails.logger.info "couldn't locate #{file_path}" - true -end - - -def virtual? - true -end - -def new? - false -end - -def compress_js? - @minimize -end - -def minimize - @minimze = true -end - -def local - @local = true -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :core do - if (source_path = find_file source_path) - Rails.logger.debug "reading file: #{source_path}" - ::File.read source_path - end - end - - def link_view opts={} - opts[:path] = { card: { type: card.type, content: card.db_content}} - link_to_card card.name, _render_title, opts - end - - def link_to_view view, text=nil, opts={} - opts[:path] = { card: { type: card.type, content: card.db_content}} - super view, (text || view), opts - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :include_tag do - card.existing_source_paths.map do |path| - javascript_include_tag(path) - end.join "\n" - end - - def short_content - fa_icon("exclamation-circle", class: "text-muted pr-2") + - wrap_with(:span, "asset file", class: "text-muted") - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/asset_file.rb ~~ diff --git a/set/mod006-content/abstract/haml_file.rb b/set/mod006-content/abstract/haml_file.rb deleted file mode 100644 index 724ecbf..0000000 --- a/set/mod006-content/abstract/haml_file.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (HamlFile) -# -module HamlFile; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/haml_file.rb"; end -def self.included host_class - host_class.mattr_accessor :template_path - host_class.extend Card::Set::Format::HamlPaths - host_class.template_path = host_class.haml_template_path -end - -def content - File.read template_path -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :input do - "Content is managed by code and cannot be edited" - end - - def haml_locals - {} - end - - view :core do - haml card.content, haml_locals - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/haml_file.rb ~~ diff --git a/set/mod006-content/abstract/lock.rb b/set/mod006-content/abstract/lock.rb deleted file mode 100644 index 6656fe1..0000000 --- a/set/mod006-content/abstract/lock.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Lock) -# -module Lock; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/lock.rb"; end -def lock - was_already_locked = locked? - return if was_already_locked - - Auth.as_bot do - lock! - yield - end -ensure - unlock! unless was_already_locked -end - -def lock_cache_key - "UPDATE-LOCK:#{key}" -end - -def locked? - Card.cache.read lock_cache_key -end - -def lock! - Card.cache.write lock_cache_key, true -end - -def unlock! - Card.cache.write lock_cache_key, false -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/lock.rb ~~ diff --git a/set/mod006-content/abstract/read_only.rb b/set/mod006-content/abstract/read_only.rb deleted file mode 100644 index 0428b4d..0000000 --- a/set/mod006-content/abstract/read_only.rb +++ /dev/null @@ -1,23 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (ReadOnly) -# -module ReadOnly; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/read_only.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :input do - "Content can't be edited." - end - - def short_content - fa_icon("exclamation-circle", class: "text-muted pr-2") + - wrap_with(:span, "read-only", class: "text-muted") - end - - def standard_submit_button - multi_card_editor? ? super : "" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/read_only.rb ~~ diff --git a/set/mod006-content/abstract/templated_nests.rb b/set/mod006-content/abstract/templated_nests.rb deleted file mode 100644 index a29b89c..0000000 --- a/set/mod006-content/abstract/templated_nests.rb +++ /dev/null @@ -1,16 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (TemplatedNests) -# -module TemplatedNests; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/templated_nests.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core do - with_nest_mode :template do - super() - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/templated_nests.rb ~~ diff --git a/set/mod006-content/abstract/vendor_code_file.rb b/set/mod006-content/abstract/vendor_code_file.rb deleted file mode 100644 index 8fe1c53..0000000 --- a/set/mod006-content/abstract/vendor_code_file.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (VendorCodeFile) -# -module VendorCodeFile; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/abstract/vendor_code_file.rb"; end -include_set Abstract::CodeFile - -def self.included host_class - Abstract::CodeFile.track_mod_name host_class, caller -end - -def source_dir - "vendor" -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/abstract/vendor_code_file.rb ~~ diff --git a/set/mod006-content/all/chunk.rb b/set/mod006-content/all/chunk.rb deleted file mode 100644 index c4936ae..0000000 --- a/set/mod006-content/all/chunk.rb +++ /dev/null @@ -1,151 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Chunk) -# -module Chunk; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/all/chunk.rb"; end -def chunks content, type=nil, named=false - content ||= self.content - all_chunks = Card::Content.new(content, self).find_chunks type - named ? all_chunks.select(&:referee_name) : all_chunks -end - -def reference_chunks content=nil, named=true - chunks content, :Reference, named -end - -# named=true rejects commented nests -def nest_chunks content=nil, named=true - chunks content, :Nest, named -end - -# named=true rejects external links (since the don't refer to a card name) -def link_chunks content=nil, named=false - chunks content, :Link, named -end - -def each_item_name_with_options content=nil - reference_chunks(content).each do |chunk| - options = chunk.respond_to?(:options) ? chunk.options : {} - yield chunk.referee_name, options - end -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def nest_chunks content=nil - content ||= _render_raw - card.nest_chunks content - end - - def nested_cards content=nil - nest_chunks(content).map(&:referee_card).uniq - end - - def edit_fields - voo.edit_structure || [] - end - - def nested_field_names content=nil - nest_chunks(content).map(&:referee_name).select { |n| field_name? n } - end - - def nested_field_cards content=nil - nested_cards(content).select { |c| field_name? c.name } - end - - def field_name? name - name.field_of? card.name - end - - # @return [Array] of Arrays. each is [nest_name, nest_options_hash] - def edit_field_configs fields_only=false - if edit_fields.present? - explicit_edit_fields_config # explicitly configured in voo or code - else - implicit_edit_fields_config fields_only # inferred from nests - end - end - - def implicit_edit_fields_config fields_only - result = [] - each_nested_chunk(fields: fields_only) do |chunk| - result << [chunk.options[:nest_name], chunk.options] - end - result - end - - def each_nested_field_chunk &block - each_nested_chunk fields: true, &block - end - - def each_nested_chunk content: nil, fields: false, uniq: true, virtual: true, &block - return unless block_given? - - chunks = prepare_nested_chunks content, fields, uniq - process_nested_chunks chunks, virtual, &block - end - - def uniq_chunks chunks - processed = ::Set.new [card.key] - chunks.select do |chunk| - key = chunk.referee_name.key - ok = !processed.include?(key) - processed << key - ok - end - end - - def field_chunks chunks - chunks.select { |chunk| field_name?(chunk.referee_name) } - end - - private - - def prepare_nested_chunks content, fields, uniq - chunks = nest_chunks content - chunks = field_chunks chunks if fields - chunks = uniq_chunks chunks if uniq - chunks - end - - def process_nested_chunks chunks, virtual, &block - chunks.each do |chunk| - process_nested_chunk chunk, virtual, &block - end - end - - def process_nested_chunk chunk, virtual, &block - if chunk.referee_card&.virtual? - process_nested_virtual_chunk chunk, &block unless virtual - else - yield chunk - end - end - - def process_virtual_chunk chunk, &block - subformat(chunk.referee_card).each_nested_field_chunk(&block) - end - - def explicit_edit_fields_config - edit_fields.map do |cardish, options| - field_mark = normalized_edit_field_mark cardish, options - options = normalized_edit_field_options options, Card::Name[field_mark] - [field_mark, options] - end - end - - def normalized_edit_field_options options, cardname - options ||= cardname - options.is_a?(String) ? { title: options } : options - end - - def normalized_edit_field_mark cardish, options - return cardish if cardish.is_a?(Card) || - (options.is_a?(Hash) && options.delete(:absolute)) - - card.name.field cardish - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/all/chunk.rb ~~ diff --git a/set/mod006-content/all/contextual_content.rb b/set/mod006-content/all/contextual_content.rb deleted file mode 100644 index add7233..0000000 --- a/set/mod006-content/all/contextual_content.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (ContextualContent) -# -module ContextualContent; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/all/contextual_content.rb"; end -def context_card - @context_card || self -end - -def with_context context_card - old_context = @context_card - @context_card = context_card if context_card - yield -ensure - @context_card = old_context -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - delegate :context_card, :with_context, to: :card - - def contextual_content context_card, options={} - view = options.delete(:view) || :core - with_context(context_card) { render! view, options } - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/all/contextual_content.rb ~~ diff --git a/set/mod006-content/all/templating.rb b/set/mod006-content/all/templating.rb deleted file mode 100644 index bacb3ea..0000000 --- a/set/mod006-content/all/templating.rb +++ /dev/null @@ -1,79 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Templating) -# -module Templating; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/all/templating.rb"; end -def is_template? - return @is_template unless @is_template.nil? - - @is_template = name.trait_name? :structure, :default -end - -def is_structure? - return @is_structure unless @is_structure.nil? - - @is_structure = name.trait_name? :structure -end - -def template - # currently applicable templating card. - # note that a *default template is never returned for an existing card. - @template ||= begin - @virtual = false - - if new_card? - new_card_template - else - structure_rule_card - end - end -end - -def default_type_id - Card.default_type_id -end - -def new_card_template - default = rule_card :default, skip_modules: true - return default unless (structure = dup_structure default&.type_id) - - @virtual = true if compound? - self.type_id = structure.type_id if assign_type_to?(structure) - structure -end - -def dup_structure type_id - dup_card = dup - dup_card.type_id = type_id || default_type_id - dup_card.structure_rule_card -end - -def assign_type_to? structure - return if type_id == structure.type_id - - structure.assigns_type? -end - -def assigns_type? - # needed because not all *structure templates govern the type of set members - # for example, X+*type+*structure governs all cards of type X, - # but the content rule does not (in fact cannot) have the type X. - pattern_code = Card.quick_fetch(name.trunk_name.tag_name)&.codename - return unless pattern_code && (set_class = Set::Pattern.find pattern_code) - - set_class.assigns_type -end - -def structure - template&.is_structure? ? template : nil -end - -def structure_rule_card - return unless (card = rule_card :structure, skip_modules: true) - - card.db_content&.strip == "_self" ? nil : card -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/all/templating.rb ~~ diff --git a/set/mod006-content/right/default.rb b/set/mod006-content/right/default.rb deleted file mode 100644 index feae6e9..0000000 --- a/set/mod006-content/right/default.rb +++ /dev/null @@ -1,43 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Default" cards -# -module Default; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/right/default.rb"; end -include_set Abstract::TemplatedNests - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :one_line_content do - raw = _render_raw - "#{card.type_name} : #{raw.present? ? raw : 'empty'}" - end - - def quick_form_opts - super.merge "data-update-foreign-slot": - ".card-slot.quick_edit-view.RIGHT-Xinput_type,"\ - ".card-slot.quick_edit-view.RIGHT-Xcontent_option"\ - ".card-slot.quick_edit-view.RIGHT-Xcontent_option_view" - end - - def quick_editor - wrap_type_formgroup do - type_field class: "type-field rule-type-field _submit-on-select" - end + - wrap_content_formgroup do - text_field :content, class: "d0-card-content _submit-after-typing" - end - end - - def visible_cardtype_groups - hash = ::Card::Set::Self::Cardtype::GROUP.slice("Text", "Data", "Upload") - hash["Organize"] = ["List", "Pointer", "Link list", "Nest list"] - hash - end -end - -def empty_ok? - true -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/right/default.rb ~~ diff --git a/set/mod006-content/right/structure.rb b/set/mod006-content/right/structure.rb deleted file mode 100644 index 8ac5fa6..0000000 --- a/set/mod006-content/right/structure.rb +++ /dev/null @@ -1,85 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Structure" cards -# -module Structure; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/right/structure.rb"; end -include_set Abstract::TemplatedNests - -def item_names args={} - item_strings(args).compact.map(&:to_name) -end - -module RssFormat; module_parent.send :register_set_format, Card::Format::RssFormat, self; extend Card::Set::AbstractFormat - def raw_feed_items - [card] - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :one_line_content do - "#{_render_type} : #{_render_raw}" - end - - def visible_cardtype_groups - hash = ::Card::Set::Self::Cardtype::GROUP.slice("Text") - hash["Organize"] = ["Search", "Nest list"] - hash - end -end - -event :update_structurees_references, :integrate, - when: :update_structurees_references? do - return unless (query = structuree_query) - - Auth.as_bot do - query.run.each(&:update_references_out) - end -end - -def update_structurees_references? - db_content_changed? || action == :delete -end - -event :reset_cache_to_use_new_structure, - before: :update_structurees_references do - Card::Cache.reset_hard - Card::Cache.reset_soft -end - -event :update_structurees_type, :finalize, - changed: :type_id, when: proc { |c| c.assigns_type? } do - update_structurees type_id: type_id -end - -def structuree_names - return [] unless (query = structuree_query(return: :name)) - - Auth.as_bot do - query.run - end -end - -def update_structurees args - # NOTE: that this is not smart about overriding templating rules - # for example, if someone were to change the type of a - # +*right+*structure rule that was overridden - # by a +*type plus right+*structure rule, the override would not be respected. - return unless (query = structuree_query(return: :id)) - - Auth.as_bot do - query.run.each_slice(100) do |id_batch| - Card.where(id: id_batch).update_all args - end - end -end - -def structuree_query args={} - set_card = trunk - return unless set_card.type_id == SetID - - set_card.fetch_query args -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/right/structure.rb ~~ diff --git a/set/mod006-content/self/default.rb b/set/mod006-content/self/default.rb deleted file mode 100644 index e4f2952..0000000 --- a/set/mod006-content/self/default.rb +++ /dev/null @@ -1,11 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Default" -# -module Default; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/self/default.rb"; end -setting_opts group: :templating, position: 2, rule_type_editable: true, - short_help_text: "type/content template for new cards" -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/self/default.rb ~~ diff --git a/set/mod006-content/self/structure.rb b/set/mod006-content/self/structure.rb deleted file mode 100644 index bfaea82..0000000 --- a/set/mod006-content/self/structure.rb +++ /dev/null @@ -1,13 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Structure" -# -module Structure; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/content/set/self/structure.rb"; end -setting_opts group: :templating, position: 2, rule_type_editable: true, - short_help_text: "control card's content / structure", - help_text: "Controls cards' content / structure. "\ - "[[http://decko.org/formatting|more]]" -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/content/set/self/structure.rb ~~ diff --git a/set/mod007-format/all/active_card.rb b/set/mod007-format/all/active_card.rb deleted file mode 100644 index e3748fa..0000000 --- a/set/mod007-format/all/active_card.rb +++ /dev/null @@ -1,14 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (ActiveCard) -# -# FIXME: -this needs a better home! -module ActiveCard; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/active_card.rb"; end -def format opts={} - opts = { format: opts.to_sym } if [Symbol, String].member? opts.class - Card::Format.new self, opts -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/active_card.rb ~~ diff --git a/set/mod007-format/all/base.rb b/set/mod007-format/all/base.rb deleted file mode 100644 index 5494cff..0000000 --- a/set/mod007-format/all/base.rb +++ /dev/null @@ -1,148 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Base) -# -module Base; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/base.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def show view, args - view ||= :core - render! view, args.merge(main_nest_options) - end - - # NAME VIEWS - - view :name, compact: true, perms: :none do - name_variant safe_name - end - - def safe_name - card&.name - end - - def name_variant name - voo.variant ? name.to_name.vary(voo.variant) : name - end - - view(:key, compact: true, perms: :none) { card.key } - view(:linkname, compact: true, perms: :none) { card.name.url_key } - view(:url, compact: true, perms: :none) { card_url _render_linkname } - - view :url_link, compact: true, perms: :none do - link_to_resource card_url(_render_linkname) - end - - view :link, compact: true, perms: :none do - link_view - end - - view :nav_link, compact: true, perms: :none do - link_view class: "nav-link" - end - - def link_view opts={} - opts[:known] = card.known? - specify_type_in_link! opts - link_to_card card.name, _render_title, opts - end - - def specify_type_in_link! opts - return if opts[:known] || !voo.type - - opts[:path] = { card: { type: voo.type } } - end - - view(:codename, compact: true) { card.codename.to_s } - view(:id, compact: true) { card.id } - view(:type, compact: true) { card.type_name } - - # DATE VIEWS - - view(:created_at, compact: true) { date_view card.created_at } - view(:updated_at, compact: true) { date_view card.updated_at } - view(:acted_at, compact: true) { date_view card.acted_at } - - def date_view date - if voo.variant - date.strftime voo.variant - else - time_ago_in_words date - end - end - - # CONTENT VIEWS - - view :raw do - structure_card&.content || _render_blank - end - - def structure_card - return nil if voo.structure == true - - voo.structure ? Card[voo.structure] : card - end - - view :core, compact: true do - process_content _render_raw - end - - view :content do - _render_core - end - - view :open_content do - _render_core - end - - view :one_line_content, compact: true do - with_nest_mode :compact do - Card::Content.smart_truncate _render_core - end - end - - view :labeled_content, unknown: :mini_unknown do - render_core - end - - view :titled_content, unknown: :blank do - render_core - end - - view :blank, compact: true, perms: :none do - "" - end - - # NOTE: content and open_content may look like they should be aliased to - # core, but it's important that they render core explicitly so that core view - # overrides work. the titled and labeled views below, however, are not - # intended for frequent override, so this shortcut is fine. - - # NAME + CONTENT VIEWS - - view :titled do - "#{card.name}\n\n#{_render_core}" - end - view :open, :titled - - view :labeled do - "#{card.name}: #{_render_labeled_content}" - end - view :closed, :labeled - - # SPECIAL VIEWS - - view :array, cache: :never do - card.item_cards(limit: 0).map do |item_card| - subformat(item_card)._render_core - end.inspect - end - - # DEPRECATED - view :naked do - Rails.logger.info "DEPRECATED: naked view (used with #{card.name} card)" - render_core - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/base.rb ~~ diff --git a/set/mod007-format/all/content.rb b/set/mod007-format/all/content.rb deleted file mode 100644 index 880cb97..0000000 --- a/set/mod007-format/all/content.rb +++ /dev/null @@ -1,77 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Content) -# -module Content; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/content.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - ONE_LINE_CHARACTER_LIMIT = 60 - - # override to customize by set - def chunk_list - :default - end - - view :one_line_content do - with_nest_mode :compact do - one_line_content - end - end - - # DEPRECATED - view :closed_content, :one_line_content - - view :raw_one_line_content do - raw_one_line_content - end - - view :label do - card.label.to_s - end - - view :smart_label, cache: :never, unknown: true do - label_with_description render_label, label_description - end - - def label_with_description label, description - return label unless description - - "#{label} #{popover_link description}" - end - - # TODO: move this into a nest once popovers are stub safe - def label_description - return unless (desc = card.field :description) - - desc.format.render_core - end - - def raw_one_line_content - cut_with_ellipsis render_raw - end - - def one_line_content - Content.smart_truncate render_core - end - - def cut_with_ellipsis text, limit=one_line_character_limit - if text.size <= limit - text - else - "#{text[0..(limit - 3)]}..." - end - end - - def one_line_character_limit - voo.size || ONE_LINE_CHARACTER_LIMIT - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :hidden_content_field, unknown: true, cache: :never do - hidden_field :content, class: "d0-card-content" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/content.rb ~~ diff --git a/set/mod007-format/all/css.rb b/set/mod007-format/all/css.rb deleted file mode 100644 index e04ad4f..0000000 --- a/set/mod007-format/all/css.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Css) -# -module Css; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/css.rb"; end -module CssFormat; module_parent.send :register_set_format, Card::Format::CssFormat, self; extend Card::Set::AbstractFormat - def default_nest_view - :raw - end - - def show view, args - view ||= :content - render! view, args - end - - view :titled do - major_comment(%( Style Card: \\"#{card.name}\\" )) + _render_core - end - - view :content do - _render_core - end - - view :unknown do - major_comment "MISSING Style Card: #{card.name}" - end - - view :import do - _render_core - end - - view :url, perms: :none do - path mark: card.name, format: :css - end - - def major_comment comment, char="-" - edge = %(/* #{char * (comment.length + 4)} */) - main = %(/* #{char} #{comment} #{char} */) - "#{edge}\n#{main}\n#{edge}\n\n" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/css.rb ~~ diff --git a/set/mod007-format/all/csv.rb b/set/mod007-format/all/csv.rb deleted file mode 100644 index 06cf45a..0000000 --- a/set/mod007-format/all/csv.rb +++ /dev/null @@ -1,103 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Csv) -# -module Csv; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/csv.rb"; end -require "csv" - -module CsvFormat; module_parent.send :register_set_format, Card::Format::CsvFormat, self; extend Card::Set::AbstractFormat - def default_nest_view - :core - end - - def default_item_view - depth.zero? ? :csv_row : :name - end - - view :core do - if (item_view_options[:view] == :name_with_fields) && focal? - title_row("item name") + name_with_field_rows - else - super() - end - end - - view :csv_row do - array = _render_raw.scan(/\{\{[^}]*\}\}/).map do |inc| - process_content(inc).strip - end - - CSV.generate_line(array).strip - # strip is because search already joins with newlines - end - - view :unknown do - "" - end - - view :name_with_fields do - CSV.generate_line name_with_fields_row - end - - def name_with_fields_row - nested_field_names.each_with_object([card.name]) do |field_name, row| - row << nest(field_name) - end - end - - def name_with_field_rows - return [] unless row_card_names.present? - - row_card_names.map do |item_name| - CSV.generate_line row_from_field_names(item_name, columns) - end.join - end - - def row_card_names - @row_cards ||= card.item_names - end - - def columns - csv_structure_card.format.nested_field_names.map(&:tag) - end - - def csv_structure_card - card.rule_card(:csv_structure) || Card.fetch(row_card_names.first) - end - - def row_from_field_names parent_name, field_names, view=:core - field_names.each_with_object([parent_name]) do |field, row| - row << nest([parent_name, field], view: view) - end - end - - def title_row extra_titles=nil - titles = column_titles extra_titles - return "" unless titles.present? - - CSV.generate_line titles.map(&:upcase) - end - - def column_titles extra_titles=nil - res = Array extra_titles - card1 = Card.fetch card.item_names(limit: 1).first - card1.nest_chunks.each do |chunk| - res << column_title(chunk.options) - end - res.compact - end - - def column_title opts - if opts[:title] - opts[:title] - elsif %w[name link].member? opts[:view] - opts[:view] - else - opts[:nest_name].to_name.tag - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/csv.rb ~~ diff --git a/set/mod007-format/all/demo.rb b/set/mod007-format/all/demo.rb deleted file mode 100644 index 471d65a..0000000 --- a/set/mod007-format/all/demo.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Demo) -# -module Demo; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/demo.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :demo do - frame do - [view_select, wrap_with(:div, view_demo, class: "demo-slot")] - end - end - - view :view_list do - %i[bar box info_bar open closed titled labeled content content_panel].map do |v| - wrap_with :p, [content_tag(:h3, v), render(v, show: :menu)] - end.flatten.join "" - end - - def demo_view - Env.params[:demo_view] || :core - end - - def view_demo - wrap(true) do - render demo_view - end - end - - def view_select - card_form :get, success: { view: :demo } do - select_tag :demo_view, - options_for_select(all_views, demo_view), - class: "_submit-on-select" - end - end - - def all_views - Card::Set::Format::AbstractFormat::ViewDefinition - .views.slice(*self.class.ancestors).values.map(&:keys).flatten.uniq - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/demo.rb ~~ diff --git a/set/mod007-format/all/error.rb b/set/mod007-format/all/error.rb deleted file mode 100644 index 871f25e..0000000 --- a/set/mod007-format/all/error.rb +++ /dev/null @@ -1,81 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Error) -# -module Error; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/error.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :compact_missing, perms: :none, compact: true do - "" - end - - view :unknown, perms: :none, cache: :never do - "" - end - - view :server_error, perms: :none do - t(:format_server_error) - end - - view :denial, perms: :none do - focal? ? t(:format_denial) : "" - end - - view :not_found, perms: :none do - error_name = card.name.present? ? safe_name : t(:format_not_found_no_name) - t(:format_not_found_named, cardname: error_name) - end - - view :bad_address, perms: :none do - root.error_status = 404 - t(:format_bad_address) - end - - view :errors do - ["Problem:", "", error_messages].flatten.join "\n" - end - - def error_messages - card.errors.map do |error| - if error.attribute == :abort - simple_error_message error.message - else - standard_error_message error - end - end - end - - # for override - def simple_error_message message - message - end - - # for override - def standard_error_message error - "#{error.attribute.to_s.upcase}: #{error.message}" - end - - def unsupported_view_error_message view - t(:format_unsupported_view, view: view, cardname: card.name) - end -end - -module JsonFormat; module_parent.send :register_set_format, Card::Format::JsonFormat, self; extend Card::Set::AbstractFormat - view :errors do - { - error_status: error_status, - errors: card.errors.each_with_object({}) { |e, h| h[e.attribute] = e.message } - } - end - - view :server_error, :errors - view :denial, :errors - view :not_found, :errors - view :bad_address do - card.errors.add :address, super() - render_error - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/error.rb ~~ diff --git a/set/mod007-format/all/export.rb b/set/mod007-format/all/export.rb deleted file mode 100644 index 1e88534..0000000 --- a/set/mod007-format/all/export.rb +++ /dev/null @@ -1,79 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Export) -# -module Export; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/export.rb"; end -module JsonFormat; module_parent.send :register_set_format, Card::Format::JsonFormat, self; extend Card::Set::AbstractFormat - # returns an array of Hashes (each in export_item view) - view :export, cache: :never do - exporting_uniques do - Array.wrap(render_export_item).concat(export_items_in_view(:export)).flatten - end - end - - def max_export_depth - Env.params[:max_export_depth].present? ? Env.params[:max_export_depth].to_i : 2 - end - - # returns an array of Hashes (each in export_item view) - view :export_items, cache: :never do - exporting_uniques do - export_items_in_view(:export).flatten - end - end - - # returns Hash with the essentials needed to import a card into a new database - view :export_item do - item = { name: card.name, type: card.type_name, content: card.content } - item[:codename] = card.codename if card.codename - track_exporting card - item - end - - def export_items_in_view view - within_max_depth do - valid_items_for_export.map do |item| - nest item, view: view - end - end - end - - def track_exporting card - return unless @exported_keys - - @exported_keys << card.key - end - - def exporting_uniques - @exported_keys ||= inherit(:exported_keys) || ::Set.new - yield - end - - # prevent recursion - def within_max_depth - @export_depth ||= inherit(:export_depth).to_i + 1 - @export_depth > max_export_depth ? [] : yield - end - - def items_for_export - nest_chunks.map do |chunk| - next if chunk.try :main? - - chunk.referee_card - end.compact - end - - def valid_items_for_export - items_for_export.flatten.reject(&:blank?).uniq.find_all do |card| - valid_export_card? card - end - end - - def valid_export_card? ecard - ecard.real? && !@exported_keys.include?(ecard.key) - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/export.rb ~~ diff --git a/set/mod007-format/all/file.rb b/set/mod007-format/all/file.rb deleted file mode 100644 index b3319ba..0000000 --- a/set/mod007-format/all/file.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (File) -# -module File; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/file.rb"; end -module FileFormat; module_parent.send :register_set_format, Card::Format::FileFormat, self; extend Card::Set::AbstractFormat - view :core do - "File rendering of this card not yet supported" - end - - view :style do - nil - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/file.rb ~~ diff --git a/set/mod007-format/all/frame.rb b/set/mod007-format/all/frame.rb deleted file mode 100644 index 8c92c8b..0000000 --- a/set/mod007-format/all/frame.rb +++ /dev/null @@ -1,58 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Frame) -# -module Frame; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/frame.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :flash, cache: :never, unknown: true, perms: :none do - flash_notice = params[:flash] || Env.success.flash - return "" unless flash_notice.present? && focal? - - Array(flash_notice).join "\n" - end - - def frame &block - standard_frame(&block) - end - - def standard_frame slot=true, &block - with_frame slot do - wrap_body(&block) if block_given? - end - end - - def with_frame slot=true, header=frame_header, slot_opts={} - voo.hide :help - add_name_context - wrap slot, slot_opts do - panel do - [header, frame_help, render_flash, (yield if block_given?)] - end - end - end - - def frame_header - _render_header - end - - def frame_help - with_class_up "help-text", "alert alert-info" do - _render :help - end - end - - def frame_and_form action, form_opts={}, &block - form_opts ||= {} - frame do - card_form action, form_opts, &block - end - end - - def panel &block - wrap_with :div, class: classy("d0-card-frame"), &block - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/frame.rb ~~ diff --git a/set/mod007-format/all/haml.rb b/set/mod007-format/all/haml.rb deleted file mode 100644 index da7d934..0000000 --- a/set/mod007-format/all/haml.rb +++ /dev/null @@ -1,84 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Haml) -# -module Haml; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/haml.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - include Card::Set::Format::HamlPaths - - define_method :the_scope do - set_scope - end - - define_method :haml_scope do - set_scope - end - - # Renders haml templates. The haml template can be passed as string or - # block or a symbol that refers to a view template. - # @param args [Hash, String, Symbol] - # If a symbol is given then a template is expected in the corresponding view - # directory. - # @return [String] rendered haml as HTML - # @example render a view template - # # view/type/basic/my_template.haml: - # %p - # Hi - # = name - # - # # set/type/basic.rb: - # view :my_view do - # haml :my_template, name: "Joe: # => "

Hi Joe

" - # end - # @example use a block to pass haml - # haml name: "Joe" do - # <<-HAML.strip_heredoc - # %p - # Hi - # = name - # HAML - # # =>

Hi Joe

- # @example create a slot in haml code - # - haml_wrap do - # %p - # some haml - - def haml *args, &block - if args.first.is_a? Symbol - process_haml_template(*args) - else - process_haml(*args, &block) - end - end - - def haml_partial partial, locals={} - locals[:template_path] ||= @template_path - process_haml_template "_#{partial}".to_sym, locals - end - - private - - def process_haml *args - args.unshift yield if block_given? - haml_to_html(*args) - end - - def process_haml_template template_name, *args - locals = args.first || {} - path = identify_template_path template_name, locals - with_template_path path do - haml_to_html ::File.read(path), *args - end - # rescue => e - # raise Card::Error, "HAML error #{template_name}: #{e.message}\n#{e.backtrace}" - end - - def identify_template_path view, locals={} - base_path = locals.delete(:template_path) || caller_locations[2].path - haml_template_path view, base_path - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/haml.rb ~~ diff --git a/set/mod007-format/all/head.rb b/set/mod007-format/all/head.rb deleted file mode 100644 index e2d36a9..0000000 --- a/set/mod007-format/all/head.rb +++ /dev/null @@ -1,170 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Head) -# -module Head; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/head.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :page_title, unknown: true, perms: :none do - title_parts = [Card::Rule.global_setting(:title)] - title_parts.unshift safe_name if card.name.present? - title_parts.join " - " - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - # add tuples containing a - # - the codename of a card with javascript config (usually in json format) - # - the name of a javascript method that handles the config - basket :mod_js_config - - view :head, unknown: true, perms: :none do - views_in_head.map { |viewname| render viewname }.flatten.compact.join "\n" - end - - def views_in_head - %i[meta_tags page_title_tag favicon_tag head_stylesheet - decko_script_variables head_javascript html5shiv_tag - script_config_and_initiation - universal_edit_button rss_links] - end - - # FIXME: tags not working with `template: :haml` - view :meta_tags, unknown: true, perms: :none do - haml :meta_tags - end - - view :html5shiv_tag, unknown: true, perms: :none do - nest :script_html5shiv_printshiv, view: :script_tag - end - - view :page_title_tag, unknown: true, perms: :none do - content_tag(:title) { render :page_title } - end - - view :favicon_tag, unknown: true, perms: :none do - nest :favicon, view: :link_tag - end - - view :universal_edit_button, unknown: true, denial: :blank, perms: :update do - return if card.new? - - tag "link", rel: "alternate", type: "application/x-wiki", - title: "Edit this page!", href: path(view: :edit) - end - - # these should render a view of the rule card - # it would then be safe to cache if combined with param handling - # (but note that machine clearing would need to reset card cache...) - view :head_stylesheet, unknown: true, cache: :never, perms: :none do - return unless (href = head_stylesheet_path) - - tag "link", href: href, media: "all", rel: "stylesheet", type: "text/css" - end - - view :head_javascript, unknown: true, cache: :never, perms: :none do - Array.wrap(head_javascript_paths).reject { |p| p.empty? }.join("\n") - end - - view :decko_script_variables, unknown: true, cache: :never, perms: :none do - string = "" - decko_script_variables.each do |k, v| - string += "#{k}=#{script_variable_to_js v};\n" - end - javascript_tag { string } - end - - def decko_script_variables - { - "window.decko": { rootUrl: card_url("") }, - "decko.doubleClick": Card.config.double_click, - "decko.cssPath": head_stylesheet_path, - "decko.currentUserId": (Auth.current_id if Auth.signed_in?) - - } - end - - def script_variable_to_js value - if value.is_a? Hash - string = "{" - value.each { |k, v| string += "#{k}:#{script_variable_to_js v}" } - "#{string}}" - else - "'#{value}'" - end - end - - def param_or_rule_card setting - if params[setting] - Card[params[setting]] - else - root.card.rule_card setting - end - end - - def debug_or_machine_path setting, debug_lambda, machine_path_lambda - return unless (asset_card = param_or_rule_card setting) - debug_path(setting, asset_card, &debug_lambda) || - machine_path_lambda.call(asset_card.machine_output_url) - end - - def debug_path setting, asset_card - return unless params[:debug] == setting.to_s - - yield asset_card - end - - def head_stylesheet_path - debug_or_machine_path :style, - ->(style_card) { path mark: style_card.name, item: :import, format: :css }, - ->(machine_path) { machine_path } - end - - def head_javascript_paths - return unless (asset_card = param_or_rule_card :script) - asset_card.item_cards.map do |script| - script.format(:html).render :javascript_include_tag - end - - # debug_or_machine_path( - # :script, - # ->(script_card) { - # script_card.item_cards.map do |script| - # script.format(:html).render :javascript_include_tag - # end - # }, - # ->(machine_path) { - # javascript_include_tag machine_path - # } - # ) - end - - view :script_config_and_initiation, unknown: true, perms: :none do - javascript_tag do - (mod_js_configs << trigger_slot_ready).join "\n\n" - end - end - - def mod_js_configs - mod_js_config.map do |codename, js_decko_function| - config_json = escape_javascript Card::Rule.global_setting(codename) - "decko.#{js_decko_function}('#{config_json}')" - end - end - - def trigger_slot_ready - "$('document').ready(function() { $('.card-slot').trigger('slotReady'); })" - end - - # TODO: move to rss mod - view :rss_links, unknown: true, perms: :none do - render :rss_link_tag if rss_link? - end - - def rss_link? - Card.config.rss_enabled && respond_to?(:rss_link_tag) - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/head.rb ~~ diff --git a/set/mod007-format/all/header.rb b/set/mod007-format/all/header.rb deleted file mode 100644 index a011c98..0000000 --- a/set/mod007-format/all/header.rb +++ /dev/null @@ -1,71 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Header) -# -# LOCALIZE first item -module Header; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/header.rb"; end -TOGGLE_MAP = { close: %w[open open], open: %w[close closed] }.freeze - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :header, perms: :none do - main_header - end - - def main_header - header_wrap _render_header_title - end - - def header_wrap content=nil - haml :header_wrap, content: (block_given? ? yield : output(content)) - end - - view :header_title, perms: :none do - header_title_elements - end - - def header_title_elements - voo.hide :title_toggle if show_view?(:icon_toggle, :hide) - title_view = show_view?(:title_toggle, :hide) ? :title_toggle : :title - [_render_icon_toggle(optional: :hide), _render(title_view)] - end - - def show_draft_link? - card.drafts.present? && @slot_view == :edit - end - - view :title_toggle, perms: :none do - content_toggle(_render_title(hide: :title_link)) - end - - view :icon_toggle, perms: :none do - direction = @toggle_mode == :close ? :expand : :collapse_down - content_toggle icon_tag(direction) - end - - view :toggle, :icon_toggle # deprecated; use icon_toggle - - def content_toggle text="" - return if text.nil? - - verb, adjective = toggle_verb_adjective - link_to_view adjective, text, title: "#{verb} #{card.name}", # LOCALIZE - class: "toggle-#{adjective} toggler nodblclick" - end - - def toggle_view - toggle_verb_adjective.last - end - - def toggle_verb_adjective - TOGGLE_MAP[@toggle_mode || :open] || - raise(Card::Error, "invalid toggle mode: #{@toggle_mode}") - end - - def structure_editable? - card.structure && card.template.ok?(:update) - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/header.rb ~~ diff --git a/set/mod007-format/all/html_content.rb b/set/mod007-format/all/html_content.rb deleted file mode 100644 index f2e016e..0000000 --- a/set/mod007-format/all/html_content.rb +++ /dev/null @@ -1,178 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (HtmlContent) -# -module HtmlContent; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/html_content.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def prepare_content_slot - class_up "card-slot", "d0-card-content" - voo.hide :menu - end - - before(:content) { prepare_content_slot } - - view :content do - voo.hide :edit_button - wrap do - [_render_menu, _render_core, _render_edit_button(edit: :inline)] - end - end - - before(:content_with_edit_button) do - prepare_content_slot - end - - view :content_with_edit_button, unknown: true do - wrap do - [_render_menu, _render_core, _render_edit_button(edit: :inline)] - end - end - - view :short_content, wrap: { div: { class: "text-muted" } } do - short_content - end - - view :raw_one_line_content, unknown: :mini_unknown, - wrap: { div: { class: "text-muted" } } do - raw_one_line_content - end - - view :one_line_content, unknown: :mini_unknown, - wrap: { div: { class: "text-muted" } } do - one_line_content - end - - before(:content_with_title) { prepare_content_slot } - - view :content_with_title do - wrap true, title: card.format(:text).render_core do - [_render_menu, _render_core] - end - end - - before :content_panel do - prepare_content_slot - class_up "card-slot", "card" - end - - view :content_panel do - wrap do - wrap_with :div, class: "card-body" do - [_render_menu, _render_core] - end - end - end - - view :titled do - @content_body = true - wrap do - [ - naming { render_header }, - render_flash, - wrap_body { render_titled_content }, - render_comment_box(optional: :hide) - ] - end - end - - view :labeled, unknown: true do - @content_body = true - wrap(true, class: "row") do - labeled(render_title, wrap_body { "#{render_menu}#{render_labeled_content}" }) - end - end - - def labeled label, content - haml :labeled, label: label, content: content - end - - def labeled_field field, item_view=:name, opts={} - opts[:title] ||= Card.fetch_name field - field_nest field, opts.merge(view: :labeled, - items: (opts[:items] || {}).merge(view: item_view)) - end - - view :open do - toggle_logic - @toggle_mode = :open - @content_body = true - frame do - [_render_open_content, render_comment_box(optional: :hide)] - end - end - - view :closed do - with_nest_mode :compact do - toggle_logic - class_up "d0-card-body", "closed-content" - @content_body = false - @toggle_mode = :close - frame - end - end - - def toggle_logic - show_view?(:title_link, :hide) ? voo.show(:icon_toggle) : voo.show(:title_toggle) - end - - def current_set_card - set_name = params[:current_set] - set_name ||= "#{card.name}+*type" if card.known? && card.type_id == Card::CardtypeID - set_name ||= "#{card.name}+*self" - Card.fetch(set_name) - end - - def raw_one_line_content - cleaned = Card::Content.clean! render_raw, {} - cut_with_ellipsis cleaned - end - - def one_line_content - # TODO: use a version of Card::Content.smart_truncate - # that counts characters instead of clean! - cleaned = Card::Content.clean! render_core, {} - cut_with_ellipsis cleaned - end - - # LOCALIZE - def short_content - short_content_items || short_content_fields || short_content_from_core - end - - def short_content_items - return unless card.respond_to? :count - - "#{count} #{'item'.pluralize count}" - end - - def short_content_fields - with_short_content_fields do |num_fields| - "#{num_fields} #{'field'.pluralize num_fields}" if num_fields.positive? - end - end - - def with_short_content_fields - yield nested_field_names.size if voo.structure || card.structure - end - - def short_content_from_core - content = render_core - if content.blank? - "empty" - elsif content.size <= 5 - content - elsif content.count("\n") < 2 - "#{content.size} characters" - else - "#{content.count("\n") + 1} lines" - end - end - - def count - @count ||= card.count - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/html_content.rb ~~ diff --git a/set/mod007-format/all/html_error.rb b/set/mod007-format/all/html_error.rb deleted file mode 100644 index 3f73ba0..0000000 --- a/set/mod007-format/all/html_error.rb +++ /dev/null @@ -1,217 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (HtmlError) -# -module HtmlError; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/html_error.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :server_error, template: :haml - - view :debug_server_error, wrap: { modal: { size: :full } } do - error_page = BetterErrors::ErrorPage.new Card::Error.current, - "PATH_INFO" => request.env["REQUEST_URI"] - haml :debug_server_error, {}, error_page - end - - view :unknown do - createable { wrap { unknown_link "#{unknown_icon} #{render_title}" } } - end - - # icon only, no wrap - view :mini_unknown, unknown: true, cache: :never do - createable { unknown_link unknown_icon } - end - - def createable - card.ok?(:create) ? yield : "" - end - - def unknown_link text - path_opts = voo.type ? { card: { type: voo.type } } : {} - link_to_view :new_in_modal, text, path: path_opts, class: classy("unknown-link") - end - - def unknown_icon - fa_icon "plus-square" - end - - view :compact_missing, perms: :none do - wrap_with :span, h(title_in_context), class: "text-muted" - end - - view :conflict, cache: :never do - actor_link = link_to_card card.last_action.act.actor.name - class_up "card-slot", "error-view" - wrap do # LOCALIZE - alert "warning" do - %( - Conflict! - #{card.last_action_id} -
#{actor_link} has also been making changes.
-
Please examine below, resolve above, and re-submit.
- #{render_act} - ) - end - end - end - - view :errors, perms: :none do - return if card.errors.empty? - - voo.title = if card.name.blank? - "Problems" - else - t(:format_problems_name, - cardname: card.name) - end - voo.hide! :menu - class_up "alert", "card-error-msg" - standard_errors voo.title - end - - view :not_found do - voo.hide! :menu - voo.title = "Not Found" - frame do - [not_found_errors, sign_in_or_up_links("to create it")] - end - end - - view :denial do - focal? ? loud_denial : quiet_denial - end - - def view_for_unknown view - main? && ok?(:create) ? :new : super - end - - def show_all_errors? - # make configurable by env - Auth.always_ok? || Rails.env.development? - end - - def error_cardname exception - cardname = super - show_all_errors? ? backtrace_link(cardname, exception) : cardname - end - - def rendering_error exception, view - wrap_with(:span, class: "render-error alert alert-danger") { super } - end - - def error_modal_id - @error_modal_id ||= unique_id - end - - def error_message exception - %{ -

Error message (visible to admin only)

-

#{CGI.escapeHTML exception.message}

-
#{exception.backtrace * "
\n"}
- } - end - - def backtrace_link cardname, exception - # TODO: make this a modal link after new modal handling is merged in - wrap_with(:span, title: error_message(exception)) { cardname } - end - - def standard_errors heading=nil - alert "warning", true do - [ - (wrap_with(:h4, heading, class: "alert-heading error") if heading), - error_messages.join("
") - ] - end - end - - def simple_error_message message - h message - end - - def standard_error_message error - "

#{h error.attribute.to_s.upcase}: #{h error.message}

" - end - - def not_found_errors - if card.errors.any? - standard_errors - else - haml :not_found - end - end - - def sign_in_or_up_links to_task - return if Auth.signed_in? - - links = [signin_link, signup_link].compact.join " #{t(:format_or)} " - wrap_with(:div) do - "#{[t(:format_please), links, to_task].join(' ')}." - end - end - - def signin_link - link_to_card :signin, t(:account_sign_in)&.downcase, - class: "signin-link", slotter: true, path: { view: :open } - end - - def signup_link - return unless signup_ok? - - link_to_card :signup, t(:account_sign_up)&.downcase, - class: "signup-link", slotter: true, path: { action: :new } - end - - def signup_ok? - Card.new(type_id: Card::SignupID).ok? :create - end - - def quiet_denial - wrap_with :span, class: "denied" do - "" - end - end - - def loud_denial - voo.hide :menu - frame do - [wrap_with(:h1, t(:format_sorry)), - wrap_with(:div, loud_denial_message)] - end - end - - def loud_denial_message - to_task = if @denied_task - t(:format_denied_task, - denied_task: @denied_task) - else - t(:format_to_do_that) - end - - case - when not_denied_task_read? - t(:format_read_only) - when Auth.signed_in? - t(:format_need_permission_task, task: to_task) - else - Env.save_interrupted_action request.env["REQUEST_URI"] - sign_in_or_up_links to_do_unauthorized_task - end - end - - def not_denied_task_read? - @denied_task != :read && Card.config.read_only - end - - def to_do_unauthorized_task - if @denied_task - t(:format_denied_task, - denied_task: @denied_task) - else - t(:format_to_do_that) - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/html_error.rb ~~ diff --git a/set/mod007-format/all/html_show.rb b/set/mod007-format/all/html_show.rb deleted file mode 100644 index 7521b2d..0000000 --- a/set/mod007-format/all/html_show.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (HtmlShow) -# -module HtmlShow; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/html_show.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def show view, args - capture_the_freak do - content = send show_method, view, args - show_full_page? ? wrap_with_html_page(content) : content - end - end - - def show_method - "show_#{show_layout? ? :with : :without}_page_layout" - end - - def show_without_page_layout view, args - @main = true if params[:is_main] || args[:main] - args.delete(:layout) - view ||= args[:home_view] || :open # default_nest_view - render! view, args - end - - def show_full_page? - !Env.ajax? - end - - wrapper :html_page do - <<-HTML.strip_heredoc - - - - #{head_content} - - #{interior} - - HTML - end - - def head_content - nest card.rule_card(:head), view: :head_content - end - - private - - # this is a temporary fix to try to debug a recurring encoding-related error - # TODO: remove the following after tracking down wikirate encoding bug - def capture_the_freak - yield - rescue Card::Error::ServerError => e - if e.message.match?(/invalid byte sequence/) - Card::Lexicon.cache.reset - Rails.logger.info "reset name cache to prevent encoding freakiness" - end - raise e - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/html_show.rb ~~ diff --git a/set/mod007-format/all/html_title.rb b/set/mod007-format/all/html_title.rb deleted file mode 100644 index b8c1854..0000000 --- a/set/mod007-format/all/html_title.rb +++ /dev/null @@ -1,56 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (HtmlTitle) -# -module HtmlTitle; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/html_title.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :title, compact: true, perms: :none do - standard_title - end - - def standard_title - name_variant title_in_context(voo.title) - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :title do - show_view?(:title_link, :hide) ? render_title_link : render_title_no_link - end - - view :title_link, compact: true, perms: :none do - link_to_card card.name, render_title_no_link - end - - view :title_no_link, compact: true, perms: :none do - wrapped_title standard_title - end - - def title_with_link link_text - link_to_card card.name, link_text - end - - def safe_name - h super - end - - def title_in_context title=nil - title = title&.html_safe - # escape titles generated from card names, but not those set explicitly - h super(title) - end - - def wrapped_title title - wrap_with :span, class: classy("card-title"), title: title do - title.to_name.parts.join wrapped_joint - end - end - - def wrapped_joint - wrap_with :span, "+", classy("joint") - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/html_title.rb ~~ diff --git a/set/mod007-format/all/html_wrapper.rb b/set/mod007-format/all/html_wrapper.rb deleted file mode 100644 index d9095ee..0000000 --- a/set/mod007-format/all/html_wrapper.rb +++ /dev/null @@ -1,173 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (HtmlWrapper) -# -module HtmlWrapper; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/html_wrapper.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - # Does two main things: - # (1) gives CSS classes for styling and - # (2) adds card data for javascript - including the "card-slot" class, - # which in principle is not supposed to be in styles - def wrap slot=true, slot_attr={}, tag=:div, &block - attrib = slot_attributes slot, slot_attr - method_wrap :wrap_with, tag, attrib, &block - end - - wrapper :slot do |opts| - class_up "card-slot", opts[:class] if opts[:class] - attrib = slot_attributes true, opts - method_wrap(:wrap_with, :div, attrib) { interior } - end - - def haml_wrap slot=true, slot_attr={}, tag=:div, &block - attrib = slot_attributes slot, slot_attr - method_wrap :haml_tag, tag, attrib, &block - end - - def method_wrap method, tag, attrib, &block - @slot_view = @current_view - debug_slot { send method, tag, attrib, &block } - end - - def slot_attributes slot, slot_attr - { id: slot_id, class: wrap_classes(slot), data: wrap_data }.tap do |hash| - add_class hash, slot_attr.delete(:class) - hash.deep_merge! slot_attr - end - end - - def slot_id - "#{card.name.safe_key}-#{@current_view}-view" - end - - def wrap_data slot=true - with_slot_data slot do - { - "card-id": card.id, - "card-name": slot_cardname, - "card-link-name": card.name.url_key, - "slot-id": SecureRandom.hex(10) - } - end - end - - def slot_cardname - name = card.name - name = card.new? && name.compound? ? name.url_key : name - h name - end - - def with_slot_data slot - hash = yield - # rails helper convert slot hash to json - # but haml joins nested keys with a dash - hash[:slot] = slot_options_json if slot - hash - end - - def slot_options_json - html_escape_except_quotes JSON(slot_options) - end - - def slot_options - options = voo ? voo.slot_options : {} - name_context_slot_option options - options - end - - def name_context_slot_option opts - return unless initial_context_names.present? - - opts[:name_context] = initial_context_names.map(&:key) * "," - end - - def debug_slot &block - debug_slot? ? debug_slot_wrap(&block) : yield - end - - def debug_slot? - params[:debug] == "slot" - end - - def debug_slot_wrap - pre = "" - [pre, "BEGIN", post, yield, pre, "END", post].join - end - - def wrap_classes slot - list = slot ? ["card-slot"] : [] - list += ["#{@current_view}-view", card.safe_set_keys] - list << "STRUCTURE-#{voo.structure.to_name.key}" if voo&.structure - classy list - end - - def wrap_body &block - wrap_with(:div, class: body_css_classes, &block) - end - - def haml_wrap_body &block - wrap_body do - capture_haml(&block) - end - end - - def body_css_classes - css_classes = ["d0-card-body"] - css_classes += ["d0-card-content", card.safe_set_keys] if @content_body - classy(*css_classes) - end - - def wrap_main - return yield if no_main_wrap? - - wrap_with :div, yield, id: "main" - end - - def no_main_wrap? - Env.ajax? || params[:layout] == "none" - end - - def wrap_with tag, content_or_args={}, html_args={}, &block - tag_args = block_given? ? content_or_args : html_args - content_tag(tag, tag_args) { content_within_wrap content_or_args, &block } - end - - def wrap_each_with tag, content_or_args={}, args={}, &block - tag_args = block_given? ? content_or_args : args - content_items_within_wrap(content_or_args, args, &block).map do |item| - wrap_with(tag, tag_args) { item } - end.join "\n" - end - - private - - def content_items_within_wrap content, args - content = block_given? ? yield(args) : content - content.compact - end - - def content_within_wrap content - content = block_given? ? yield : content - output(content).to_s.html_safe - end - - def html_escape_except_quotes string - # to be used inside single quotes (makes for readable json attributes) - string.to_s.gsub(/&/, "&") - .gsub(/'/, "'") - .gsub(/>/, ">") - .gsub(/ - # it treats opts other than "path" as html opts for that tag, - # and it adds special handling of "remote" and "method" opts - # (changes them into data attributes) - def link_to text=nil, opts={} - opts[:href] ||= path opts.delete(:path) - text = raw(text || opts[:href]) - interpret_data_opts_to_link_to opts - wrap_with :a, text, opts - end - - # in HTML, #link_to_card adds special css classes indicated whether a - # card is "known" (real or virtual) or "wanted" (unknown) - # TODO: upgrade from (known/wanted)-card to (real/virtual/unknown)-card - def link_to_card cardish, text=nil, opts={} - name = Card::Name[cardish] - slotterify opts if opts[:slotter] - add_known_or_wanted_class opts, name - super name, (text || name), opts - end - - # in HTML, #link_to_view defaults to a remote link with rel="nofollow". - def link_to_view view, text=nil, opts={} - slotterify opts - super view, (text || view), opts - end - - # in HTML, #link_to_resource automatically adds a target to external resources - # so they will open in another tab. It also adds css classes indicating whether - # the resource is internal or external - def link_to_resource resource, text=nil, opts={} - add_resource_opts opts, resource_type(resource) - super - end - - private - - def slotterify opts - opts.delete(:slotter) - opts.reverse_merge! remote: true, rel: "nofollow" - add_class opts, "slotter" - end - - def add_known_or_wanted_class opts, name - known = opts.delete :known - known = Card.known?(name) if known.nil? - add_class opts, (known ? "known-card" : "wanted-card") - end - - def interpret_data_opts_to_link_to opts - %i[remote method].each do |key| - next unless (val = opts.delete key) - - opts["data-#{key}"] = val - end - end - - def add_resource_opts opts, resource_type - opts[:target] ||= "_blank" if resource_type == "external-link" - add_class opts, resource_type - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/links.rb ~~ diff --git a/set/mod007-format/all/menu.rb b/set/mod007-format/all/menu.rb deleted file mode 100644 index a3ae7d0..0000000 --- a/set/mod007-format/all/menu.rb +++ /dev/null @@ -1,138 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Menu) -# -module Menu; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/menu.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :menu, denial: :blank, unknown: true do - return "" if card.unknown? - - wrap_with :div, class: "card-menu #{menu_link_classes}" do - [render_help_link, - menu_link, - (voo.show?(:bridge_link) ? bridge_link(false) : nil)] - end - end - - def menu_link - case voo.edit - when :inline - edit_inline_link - when :full - edit_in_bridge_link - else # :standard - edit_link - end - end - - def edit_view - case voo.edit - when :inline - :edit_inline - when :full - :edit - else # :standard - edit_link - end - end - - view :edit_link, unknown: true, denial: :blank do - edit_link edit_link_view - end - - def edit_link_view - :edit - end - - view :full_page_link do - full_page_link - end - - view :bridge_link, unknown: true do - bridge_link - end - - def bridge_link in_modal=true - opts = { class: "bridge-link" } - if in_modal - # add_class opts, "close" - opts["data-slotter-mode"] = "modal-replace" - end - link_to_view :bridge, material_icon(:more_horiz), opts - end - - # no caching because help_text view doesn't cache, and we can't have a - # stub in the data-content attribute or it will get html escaped. - view :help_link, cache: :never, unknown: true do - help_link render_help_text, help_title - end - - def help_link text=nil, title=nil - opts = help_popover_opts text, title - add_class opts, "_card-menu-popover" - link_to help_icon, opts - end - - def help_popover_opts text=nil, title=nil - text ||= render_help_text - opts = { "data-placement": :left, class: "help-link" } - popover_opts text, title, opts - end - - def help_icon - material_icon("help") - end - - def help_title - "#{name_parts_links} (#{render_type}) #{full_page_link unless card.simple?}" - end - - def name_parts_links - card.name.parts.map do |part| - link_to_card part - end.join Card::Name.joint - end - - def full_page_link - link_to_card full_page_card, full_page_icon, class: classy("full-page-link") - end - - def full_page_card - card - end - - def edit_in_bridge_link opts={} - edit_link :bridge, opts - end - - def edit_link view=:edit, opts={} - link_to_view view, opts.delete(:link_text) || menu_icon, - edit_link_opts(opts.reverse_merge(modal: :lg)) - end - - # @param modal [Symbol] modal size - def edit_link_opts modal: nil - opts = { class: classy("edit-link") } - if modal - opts[:"data-slotter-mode"] = "modal" - opts[:"data-modal-class"] = "modal-#{modal}" - end - opts - end - - def menu_link_classes - "nodblclick#{show_view?(:hover_link) ? ' _show-on-hover' : ''}" - end - - def menu_icon - material_icon "edit" - end - - def full_page_icon - icon_tag :open_in_new - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/menu.rb ~~ diff --git a/set/mod007-format/all/path.rb b/set/mod007-format/all/path.rb deleted file mode 100644 index ac2a1b7..0000000 --- a/set/mod007-format/all/path.rb +++ /dev/null @@ -1,88 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Path) -# -module Path; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/path.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - # Decko uses the term "path" a bit unusually. - # - # In most formats, #path returns a full url. In HTML, it provides everything after - # the domain/port. - # - # If you're feeling saucy, you might point out that typically "paths" don't - # include queries and fragment identifiers, much less protocols, domains, and ports. - # 10 pedantry points to you! But "path" is easy to type and the method is smart about - # format needs, so using it will lead you down the right ... something or other. - - # Format#path is for generating standard card routes, eg, assuming the card - # associated with the current format is named "current", it will generate paths like - # these: - - # path view: :bar -> "current?view=bar" - # path mark: [mycardid] -> "mycardname" - # path format: :csv) -> "current.csv" - # path action: :update -> "update/current" - - # #path produces paths that follow one of three main patterns: - - # 1. mark[.format][?query] # standard GET request - # 2. action/mark[?query] # GET variant of standard actions - # 3. new/mark # shortcut for "new" view of cardtype - - # @param opts [Hash, String] a String is treated as a complete path and - # bypasses all processing - # @option opts [String, Card::Name, Integer, Symbol, Card] :mark - # @option opts [Symbol] :action card action (:create, :update, :delete) - # @option opts [Symbol] :format - # @option opts [Hash] :card - # @option opts [TrueClass] :no_mark - - def path opts={} - return opts unless opts.is_a? Hash - - path = Card::Path.new(card, opts)&.render - contextualize_path path - end - - # in base format (and therefore most other formats), even internal paths - # are rendered as absolute urls. - def contextualize_path relative_path - card_url relative_path - end -end - -module JsonFormat; module_parent.send :register_set_format, Card::Format::JsonFormat, self; extend Card::Set::AbstractFormat - def add_unknown_name_to_opts name, opts - # noop - end -end - -module CssFormat; module_parent.send :register_set_format, Card::Format::CssFormat, self; extend Card::Set::AbstractFormat - def contextualize_path relative_path - if Card.config.file_storage == :local - # absolute paths lead to invalid assets path in css for cukes - card_path relative_path - else - # ...but relative paths are problematic when machine output and - # hard-coded assets (like fonts) are on different servers - card_url relative_path - end - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - # in HTML, decko paths rendered as relative to the site's root. - def contextualize_path relative_path - card_path relative_path - end -end - -module EmailHtmlFormat; module_parent.send :register_set_format, Card::Format::EmailHtmlFormat, self; extend Card::Set::AbstractFormat - def contextualize_path relative_path - card_url relative_path - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/path.rb ~~ diff --git a/set/mod007-format/all/rich_html.rb b/set/mod007-format/all/rich_html.rb deleted file mode 100644 index 4f4b0ec..0000000 --- a/set/mod007-format/all/rich_html.rb +++ /dev/null @@ -1,25 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (RichHtml) -# -module RichHtml; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/rich_html.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - delegate :class_up, :class_down, :with_class_up, :without_upped_class, :classy, - to: :voo - - view :type, unknown: true do - link_to_card card.type_card, nil, class: "cardtype" - end - - view :type_info do - return unless card.type_code != :basic - - wrap_with :span, class: "type-info float-right" do - link_to_card card.type_name, nil, class: "navbar-link" - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/rich_html.rb ~~ diff --git a/set/mod007-format/all/rss.rb b/set/mod007-format/all/rss.rb deleted file mode 100644 index 475b047..0000000 --- a/set/mod007-format/all/rss.rb +++ /dev/null @@ -1,86 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Rss) -# -module Rss; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/rss.rb"; end -module RssFormat; module_parent.send :register_set_format, Card::Format::RssFormat, self; extend Card::Set::AbstractFormat - attr_accessor :xml - - def initialize card, args - super - @xml = @parent ? @parent.xml : ::Builder::XmlMarkup.new - end - - def show view, args - view ||= :feed - render! view, args - end - - # FIXME: integrate this with common XML features when it is added - view :feed, cache: :never do - return "RSS feeds disabled" unless Cardio.config.rss_enabled - - begin - @xml.instruct! :xml, version: "1.0", standalone: "yes" - @xml.rss version: "2.0", - "xmlns:content" => "http://purl.org/rss/1.0/modules/content/" do - @xml.channel do - @xml.title render_feed_title - @xml.description render_feed_description - @xml.link render_url - render_feed_body - end - end - rescue StandardError => e - @xml.error "\n\nERROR rendering RSS: #{e.inspect}\n\n #{e.backtrace}" - end - end - - def raw_feed_items - [card] - end - - view :feed_body, cache: :never do - raw_feed_items.each do |item| - @xml.item do - subformat(item).render! :feed_item - end - end - end - - view :feed_title do - "#{Card::Rule.global_setting(:title)} : #{card.name.gsub(/^\*/, '')}" - end - - view :feed_item do - @xml.title card.name - add_name_context - @xml.description render_feed_item_description - @xml.pubDate pub_date - @xml.link render_url - @xml.guid render_url - end - - def pub_date - (card.updated_at || Time.zone.now).to_s(:rfc822) - # updated_at fails on virtual - # cards, because not all to_s's take args (just actual dates) - end - - view :feed_item_description do - render_open_content - end - - view(:feed_description) { "" } - view(:comment_box) { "" } - view(:menu) { "" } - - view :open, :titled, mod: All::Base::Format - view :content, :core, mod: All::Base::Format - view :open_content, :core, mod: All::Base::Format - view :closed, :link, mod: All::Base::Format -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/rss.rb ~~ diff --git a/set/mod007-format/all/text.rb b/set/mod007-format/all/text.rb deleted file mode 100644 index 265a3d5..0000000 --- a/set/mod007-format/all/text.rb +++ /dev/null @@ -1,15 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Text) -# -module Text; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/all/text.rb"; end -module TextFormat; module_parent.send :register_set_format, Card::Format::TextFormat, self; extend Card::Set::AbstractFormat - view :core do - HTMLEntities.new.decode strip_tags(super()).to_s - # need this string method to get out of html_safe mode - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/all/text.rb ~~ diff --git a/set/mod007-format/self/home.rb b/set/mod007-format/self/home.rb deleted file mode 100644 index 9c264df..0000000 --- a/set/mod007-format/self/home.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Home" -# -module Home; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/self/home.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :home_url, perms: :none do - card_url "" - end - - view :home_path, perms: :none do - card_path "" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/self/home.rb ~~ diff --git a/set/mod007-format/type/cardtype.rb b/set/mod007-format/type/cardtype.rb deleted file mode 100644 index 8065f58..0000000 --- a/set/mod007-format/type/cardtype.rb +++ /dev/null @@ -1,98 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Cardtype" cards -# -module Cardtype; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/cardtype.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :type, unknown: true do - link_to_card card.type_card, nil, class: "cardtype" - end - - def type_formgroup args={} - if card.cards_of_type_exist? - wrap_with :div, t(:format_cards_exist, scope: "core", cardname: safe_name) - else - super - end - end - - view :add_link do - add_link - end - - view :add_button do - add_link class: "btn btn-secondary" - end - - def add_link opts={} - voo.title ||= t(:format_add_card, cardname: safe_name) - link_to render_title, add_link_opts(opts) - end - - def add_link_opts opts - modal = opts.delete :modal - if modal.nil? || modal - modal_link_opts opts.merge(path: add_path(:new_in_modal)) - else - opts.merge path: add_path(:new) - end - end - - view :add_url do - card_url _render_add_path - end - - def add_path view - path_args = { mark: card.name } - process_voo_params(path_args) if voo.params - if view == :new - path_args[:action] = :new - else - path_args[:action] = :type - path_args[:view] = view - end - path path_args - end - - # don't cache because it depends on update permission for another card - view :configure_link, cache: :never, perms: ->(fmt) { fmt.can_configure? } do - configure_link - end - - def can_configure? - Card.fetch(card, :type, :structure, new: {}).ok? :update - end - - view :configure_button, cache: :never, - denial: :blank, - perms: ->(fmt) { fmt.can_configure? } do - configure_link "btn btn-secondary" - end - - def configure_link css_class=nil - return "" unless Card.fetch(card, :type, :structure, new: {}).ok? :update - - voo.title ||= t(:format_configure_card, cardname: safe_name.pluralize) - title = _render_title - link_to_card card, title, - path: { view: :bridge, - bridge: { tab: :rules_tab }, - set: Card::Name[safe_name, :type] }, - class: css_classes("configure-type-link ml-3", css_class) - end - - private - - def process_voo_params path_args - context = (@parent&.card || card).name - Rack::Utils.parse_nested_query(voo.params).each do |key, value| - value = value.to_name.absolute(context) if value - key = key.to_name.absolute(context) - path_args[key] = value - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/cardtype.rb ~~ diff --git a/set/mod007-format/type/html.rb b/set/mod007-format/type/html.rb deleted file mode 100644 index 0b8de61..0000000 --- a/set/mod007-format/type/html.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Html" cards -# -module Html; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/html.rb"; end -def clean_html? - false -end - -def diff_args - { diff_format: :raw } -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :one_line_content do - raw_one_line_content - end - - def chunk_list - :references - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - :ace_editor - end - - view :one_line_content, wrap: {} do - raw_one_line_content - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/html.rb ~~ diff --git a/set/mod007-format/type/json.rb b/set/mod007-format/type/json.rb deleted file mode 100644 index 9e0ca47..0000000 --- a/set/mod007-format/type/json.rb +++ /dev/null @@ -1,50 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Json" cards -# -# include_set Abstract::Pointer -module Json; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/json.rb"; end - -event :validate_json, :validate, on: :save, changed: :content do - check_json_syntax if content.present? -end - -def check_json_syntax - parse_content -rescue JSON::ParserError => e - errors.add t(:format_invalid_json), e.message.sub(/^\d+: /, "").to_s -end - -def parse_content - JSON.parse content -end - -def item_names _args={} - parse_content.keys.map(&:to_name) -end - -def item_values - parse_content.values -end - -def item_value name - parse_content[name] -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core do - process_content ::CodeRay.scan(_render_raw, :json).div - end - - def input_type - :ace_editor - end - - def ace_mode - :json - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/json.rb ~~ diff --git a/set/mod007-format/type/number.rb b/set/mod007-format/type/number.rb deleted file mode 100644 index 0d3f49c..0000000 --- a/set/mod007-format/type/number.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Number" cards -# -module Number; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/number.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - :text_field - end -end - -event :validate_number, :validate, on: :save do - unless valid_number?(content) - errors.add :content, - t(:format_not_numeric, content: content) - end -end - -def valid_number? string - return true if string.empty? - - valid = true - begin - Kernel.Float(string) - rescue ArgumentError, TypeError - valid = false - end - valid -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/number.rb ~~ diff --git a/set/mod007-format/type/phrase.rb b/set/mod007-format/type/phrase.rb deleted file mode 100644 index 01b9cd5..0000000 --- a/set/mod007-format/type/phrase.rb +++ /dev/null @@ -1,14 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Phrase" cards -# -module Phrase; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/phrase.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - :text_field - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/phrase.rb ~~ diff --git a/set/mod007-format/type/plain_text.rb b/set/mod007-format/type/plain_text.rb deleted file mode 100644 index 590b1b5..0000000 --- a/set/mod007-format/type/plain_text.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "PlainText" cards -# -module PlainText; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/plain_text.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - :text_area - end - - view :core do - process_content CGI.escapeHTML(_render_raw) - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/plain_text.rb ~~ diff --git a/set/mod007-format/type/toggle.rb b/set/mod007-format/type/toggle.rb deleted file mode 100644 index dd4b83c..0000000 --- a/set/mod007-format/type/toggle.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Toggle" cards -# -module Toggle; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/toggle.rb"; end -def checked? - content == "1" -end - -view :core do - case card.content.to_i - when 1 then t(:format_toggle_yes) - when 0 then t(:format_toggle_no) - else - "?" - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :input do - toggle - end - - view :labeled_editor do - toggle + toggle_label - end - - def toggle - check_box :content - end - - def toggle_label - label :content, card.name.tag - end - - def one_line_content - short_content - end - - def short_content - render_core - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/toggle.rb ~~ diff --git a/set/mod007-format/type/uri.rb b/set/mod007-format/type/uri.rb deleted file mode 100644 index a86c1c0..0000000 --- a/set/mod007-format/type/uri.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Uri" cards -# -module Uri; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/format/set/type/uri.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :core do - link_to_resource _render_raw, render_title - end - - view :url_link do - link_to_resource _render_raw - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - :text_field - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/format/set/type/uri.rb ~~ diff --git a/set/mod008-list/abstract/01_pointer.rb b/set/mod008-list/abstract/01_pointer.rb deleted file mode 100644 index b0aeac8..0000000 --- a/set/mod008-list/abstract/01_pointer.rb +++ /dev/null @@ -1,19 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Pointer) -# -module Pointer; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer.rb"; end -include_set Abstract::Paging -include_set Abstract::Items - -def diff_args - { diff_format: :pointer } -end - -def count - item_strings.size -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer.rb ~~ diff --git a/set/mod008-list/abstract/01_pointer/events.rb b/set/mod008-list/abstract/01_pointer/events.rb deleted file mode 100644 index 58e5dc0..0000000 --- a/set/mod008-list/abstract/01_pointer/events.rb +++ /dev/null @@ -1,80 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract; module Pointer; -# Set: Abstract (Pointer, Events) -# -module Events; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/events.rb"; end -event :add_and_drop_items, :prepare_to_validate, on: :save do - adds = Env.params["add_item"] - drops = Env.params["drop_item"] - Array.wrap(adds).each { |i| add_item i } if adds - Array.wrap(drops).each { |i| drop_item i } if drops -end - -event :insert_item_event, :prepare_to_validate, on: :save, when: :item_to_insert do - index = Env.params["item_index"] || 0 - insert_item index.to_i, item_to_insert -end - -def item_to_insert - Env.params["insert_item"] -end - -# If a card's type and content are updated in the same action, the new module -# will override the old module's events and functions. But this event is only -# on pointers -- other type cards do not have this event, -# Therefore if something is changed from a pointer and its content is changed -# in the same action, this event will be run and will treat the content like -# it' still pointer content. The "when" clause helps with that (but is a hack) -event :standardize_items, :prepare_to_validate, - on: :save, changed: :content, when: :still_pointer? do - items_to_content item_strings -end - -def still_pointer? - type_id == PointerID - # Card.new(type_id: type_id).is_a? Abstract::Pointer -end - -def changed_item_names - dropped_item_names + added_item_names -end - -def dropped_item_names - return item_names if trash - return [] unless (old_content = db_content_before_act) - - old_items = item_names content: old_content - old_items - item_names -end - -def added_item_names - return [] if trash - return item_names unless (old_content = db_content_before_act) - - old_items = item_names content: old_content - item_names - old_items -end - -# TODO: refactor. many of the above could be written more elegantly with improved -# handling of :content in item_names. If content is nil here, we would expect an -# empty set of cards, but in fact we get items based on self.content. - -def changed_item_cards - dropped_item_cards + added_item_cards -end - -def dropped_item_cards - return [] unless db_content_before_act - - all_item_cards item_names: dropped_item_names -end - -def added_item_cards - return item_cards unless db_content_before_act - - all_item_cards item_names: added_item_names -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/events.rb ~~ diff --git a/set/mod008-list/abstract/01_pointer/html_views.rb b/set/mod008-list/abstract/01_pointer/html_views.rb deleted file mode 100644 index 2f79941..0000000 --- a/set/mod008-list/abstract/01_pointer/html_views.rb +++ /dev/null @@ -1,131 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract; module Pointer; -# Set: Abstract (Pointer, HtmlViews) -# -module HtmlViews; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/html_views.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core, cache: :never do - standard_pointer_core - end - - view :item_cores, cache: :never do - card.known_item_cards.map do |item| - nest item, view: :core - end.join "\n" - end - - def standard_pointer_core - with_paging do |paging_args| - wrap_with :div, standard_pointer_items(paging_args), class: "pointer-list" - end - end - - def standard_pointer_items paging_args - pointer_items(paging_args.extract!(:limit, :offset)).join(voo.separator || "\n") - end - - view :one_line_content do - item_view = implicit_item_view - item_view = item_view == "name" ? "name" : "link" - wrap_with :div, class: "pointer-list" do - # limit to first 10 items to optimize - pointer_items(view: item_view, limit: 10, offset: 0).join ", " - end - end - - def wrap_item rendered, item_view - %(
#{rendered}
) - end - - view :input do - _render_hidden_content_field + super() - end - - def default_input_type - :list - end - - view :list, cache: :never do - list_input - end - - # view :nav_item do - # nav_dropdown - # end - - def list_input args={} - items = items_for_input args[:item_list] - extra_class = "pointer-list-ul" - ul_classes = classy "pointer-list-editor", extra_class - haml :list_input, items: items, ul_classes: ul_classes, - options_card: options_card_name - end - - %i[autocomplete checkbox radio select multiselect].each do |editor_view| - view(editor_view) { send "#{editor_view}_input" } - end - - def autocomplete_input - haml :autocomplete_input, item: items_for_input.first, options_card: options_card_name - end - - def checkbox_input - haml :checkbox_input, submit_on_change: @submit_on_change - end - - def radio_input - haml :radio_input, submit_on_change: @submit_on_change - end - - def select_input - options = { "-- Select --" => "" }.merge card.options_hash - select_tag("pointer_select-#{unique_id}", - options_for_select(options, card.item_name), - class: "pointer-select form-control") - end - - def multiselect_input - select_tag "pointer_multiselect-#{unique_id}", - options_for_select(card.options_hash, card.item_names), - multiple: true, class: "pointer-multiselect form-control" - end - - def add_item_modal_link - modal_link "Add Item", - size: :large, - class: "btn btn-sm btn-outline-secondary _add-item-link", - path: { view: :filter_items_modal, - item: implicit_item_view, - filter_card: filter_card.name, - slot_selector: filtered_list_slot_class, - item_selector: "_filtered-list-item", - slot: { hide: [:modal_footer] }, - filter: { not_ids: not_ids_value } } - end - - def not_ids_value - card.item_ids.map(&:to_s).join(",") - end - - def add_item_overlay_link; end - - def one_line_content - if count == 1 - card.first_name - else - short_content - end - end - - private - - # currently only used by :list and :autocomplete. could be generalized? - def items_for_input items=nil - items ||= card.item_names context: :raw - items.empty? ? [""] : items - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/html_views.rb ~~ diff --git a/set/mod008-list/abstract/01_pointer/html_views/filter.rb b/set/mod008-list/abstract/01_pointer/html_views/filter.rb deleted file mode 100644 index f6e5685..0000000 --- a/set/mod008-list/abstract/01_pointer/html_views/filter.rb +++ /dev/null @@ -1,72 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract; module Pointer;; module HtmlViews; -# Set: Abstract (Pointer, HtmlViews, Filter) -# -module Filter; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/html_views/filter.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :filtered_list, unknown: true do - filtered_list_input - end - - view :filter_items_modal, unknown: true, wrap: :modal do - render_filter_items - end - - view :filter_items, unknown: true, wrap: :slot, template: :haml - - def filtered_list_input - with_nest_mode :normal do - class_up "card-slot", filtered_list_slot_class - with_class_up "card-slot", filtered_list_slot_class do - wrap do - haml :filtered_list_input - end - end - end - end - - # NOCACHE because params alter view - view :add_selected_link, cache: :never, unknown: true do - link_to "Add Selected", - path: { filter_card: params[:filter_card] }, - class: "_add-selected slotter _close-modal btn btn-primary disabled", - data: { "slot-selector": ".#{params[:slot_selector]}", - "item-selector": ".#{params[:item_selector]}", - remote: true } - end - - def filtered_list_item item_card - nest_item item_card do |rendered, item_view| - wrap_item rendered, item_view - end - end - - # for override - # @return [Card] search card on which filtering is based - def filter_card - filter_card_from_params || default_filter_card - end - - def default_filter_card - fcard = card.options_rule_card || Card[:all] - return fcard if fcard.respond_to? :cql_hash - - fcard.fetch :referred_to_by, new: {} - end - - def filter_card_from_params - return unless params[:filter_card] - - Card.fetch params[:filter_card], new: {} - end - - # currently actually used as a class - # (because we don't have api to override slot's id) - def filtered_list_slot_class - @filtered_list_slot_class ||= "filtered-list-#{unique_id}" - end -end -end;end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/html_views/filter.rb ~~ diff --git a/set/mod008-list/abstract/01_pointer/options_api.rb b/set/mod008-list/abstract/01_pointer/options_api.rb deleted file mode 100644 index 8837178..0000000 --- a/set/mod008-list/abstract/01_pointer/options_api.rb +++ /dev/null @@ -1,87 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract; module Pointer; -# Set: Abstract (Pointer, OptionsApi) -# -# TODO: some of this should be moved to right/options!! -module OptionsApi; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/options_api.rb"; end -# or to type/JSON? - -def options_hash - json_options? ? options_card.parse_content : option_hash_from_names -end - -def json_options? - options_card&.type_id == JsonID -end - -def option_hash_from_names - option_names.each_with_object({}) do |name, hash| - hash[name] = name - end -end - -def option_names - if (selected_options = item_names) - (standard_option_names + selected_options).uniq - else - standard_option_names - end -end - -def option_cards - option_names.map do |name| - Card.fetch name, new: {} - end -end - -def options_rule_card - rule_card :content_options -end - -def standard_option_names - if json_options? - options_hash.values.map(&:to_name) - else - option_names_from_items - end -end - -def option_names_from_items - o_card = options_card - limit = o_card.try(:default_limit).to_i - o_card.item_names context: name, limit: limit -end - -def options_card - options_rule_card || Card[:all] -end - -def options_card_name - options_rule_card&.name&.url_key || ":all" -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def options_card_name - card.options_card_name - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def option_label option_name, id - %() - end - - def option_view - @option_view ||= card.rule(:content_option_view) || :smart_label - end - - def option_label_text option_name - return option_name unless (option_card = Card.fetch option_name) - - nest option_card, view: option_view - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/options_api.rb ~~ diff --git a/set/mod008-list/abstract/01_pointer/other_views.rb b/set/mod008-list/abstract/01_pointer/other_views.rb deleted file mode 100644 index 9f4a506..0000000 --- a/set/mod008-list/abstract/01_pointer/other_views.rb +++ /dev/null @@ -1,112 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract; module Pointer; -# Set: Abstract (Pointer, OtherViews) -# -# BASE views -module OtherViews; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/other_views.rb"; end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def default_limit - 20 - end - - def item_links args={} - card.item_cards(args).map do |item_card| - subformat(item_card).render_link - end - end - - def nest_item_array - card.item_cards.map do |item| - nest_item item - end - end - - view :core do - pointer_items.join ", " - end - - def pointer_items args={} - page_args = args.extract! :limit, :offset - listing card.item_cards(page_args), args - end -end - -# JavaScript views - -module JsFormat; module_parent.send :register_set_format, Card::Format::JsFormat, self; extend Card::Set::AbstractFormat - view :core do - nest_item_array.join "\n\n" - end -end - -# Data views - -module DataFormat; module_parent.send :register_set_format, Card::Format::DataFormat, self; extend Card::Set::AbstractFormat - view :core do - nest_item_array - end -end - -# JSON views - -module JsonFormat; module_parent.send :register_set_format, Card::Format::JsonFormat, self; extend Card::Set::AbstractFormat - view :content do - card.item_names - end - - def item_cards - card.item_cards - end - - def max_depth - params[:max_depth] || 1 - end - - def items_for_export - card.item_cards - end - - def essentials - return {} if depth > max_depth - - card.item_cards.map do |item| - nest item, view: :essentials - end - end - - view :links do - [] - end -end - -# CSS views - -module CssFormat; module_parent.send :register_set_format, Card::Format::CssFormat, self; extend Card::Set::AbstractFormat - # generalize to all collections? - def default_item_view - :content - end - - view :titled do - %(#{major_comment "STYLE GROUP: \"#{card.name}\"", '='}#{_render_core}) - end - - view :core do - nest_item_array.join "\n\n" - end - - view :content, :core -end - -# RSS views - -module RssFormat; module_parent.send :register_set_format, Card::Format::RssFormat, self; extend Card::Set::AbstractFormat - def raw_feed_items - @raw_feed_items ||= card.item_cards(limit: limit, offset: offset) - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/01_pointer/other_views.rb ~~ diff --git a/set/mod008-list/abstract/code_pointer.rb b/set/mod008-list/abstract/code_pointer.rb deleted file mode 100644 index 65c25ca..0000000 --- a/set/mod008-list/abstract/code_pointer.rb +++ /dev/null @@ -1,44 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (CodePointer) -# -module CodePointer; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/code_pointer.rb"; end -include_set Abstract::Pointer - -abstract_basket :item_codenames - -# simplify api -# Self::MyCodePointerSet.add_item :my_item_codename -# instead of -# Self::MyCodePointerSet.add_to_basket :item_codenames, :my_item_codename -module ClassMethods - def add_item codename - valid_codename codename do - add_to_basket :item_codenames, codename - end - end - - def unshift_item codename - valid_codename codename do - unshift_basket :item_codenames, codename - end - end - - def valid_codename codename - if Card::Codename.exist? codename - yield - else - Rails.logger.info "unknown codename '#{codename}' added to code pointer" - end - end -end - -def content - item_codenames.map do |codename| - Card.fetch_name codename - end.compact.to_pointer_content -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/code_pointer.rb ~~ diff --git a/set/mod008-list/abstract/id_pointer.rb b/set/mod008-list/abstract/id_pointer.rb deleted file mode 100644 index 926b240..0000000 --- a/set/mod008-list/abstract/id_pointer.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (IdPointer) -# -# store items as ids, not names -module IdPointer; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/abstract/id_pointer.rb"; end - -def standardize_item cardish - if (id = Card.id cardish) - "~#{id}" - else - Rails.logger.info "no id for '#{cardish}' added to id pointer" - nil - end -end - -def item_ids args={} - item_strings(args).map do |item| - item = standardize_item item unless item.match?(/^~/) - item.to_s.tr("~", "").to_i - end.compact -end - -def item_names args={} - item_ids(args).map(&:cardname).compact -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/abstract/id_pointer.rb ~~ diff --git a/set/mod008-list/all/supports_content_options.rb b/set/mod008-list/all/supports_content_options.rb deleted file mode 100644 index e8308ec..0000000 --- a/set/mod008-list/all/supports_content_options.rb +++ /dev/null @@ -1,16 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (SupportsContentOptions) -# -module SupportsContentOptions; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/all/supports_content_options.rb"; end -def supports_content_options? - false -end - -def supports_content_option_view? - false -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/all/supports_content_options.rb ~~ diff --git a/set/mod008-list/right/content_option_view.rb b/set/mod008-list/right/content_option_view.rb deleted file mode 100644 index 130e0ce..0000000 --- a/set/mod008-list/right/content_option_view.rb +++ /dev/null @@ -1,19 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+ContentOptionView" cards -# -module ContentOptionView; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/right/content_option_view.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def quick_edit - if card.left.prototype_default_card&.try(:show_content_options?) && - card.left.prototype.rule_card(:input_type)&.supports_content_option_view? - super - else - "" - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/right/content_option_view.rb ~~ diff --git a/set/mod008-list/right/content_options.rb b/set/mod008-list/right/content_options.rb deleted file mode 100644 index 96dfbd6..0000000 --- a/set/mod008-list/right/content_options.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+ContentOptions" cards -# -module ContentOptions; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/right/content_options.rb"; end -def default_limit - cql_limit = fetch_query.limit if respond_to?(:fetch_query) - cql_limit || 50 -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def quick_edit - card.left.prototype_default_card.try(:show_content_options?) ? super : "" - end - - def quick_editor - wrap_type_formgroup do - type_field class: "type-field rule-type-field _submit-on-select" - end + - wrap_content_formgroup do - text_field :content, class: "d0-card-content _submit-after-typing" - end - end - - def visible_cardtype_groups - { "Organize" => %w[List Pointer] } - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/right/content_options.rb ~~ diff --git a/set/mod008-list/self/content_option_view.rb b/set/mod008-list/self/content_option_view.rb deleted file mode 100644 index 3c8ce8c..0000000 --- a/set/mod008-list/self/content_option_view.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "ContentOptionView" -# -module ContentOptionView; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/self/content_option_view.rb"; end -setting_opts group: :editing, position: 6, - restricted_to_type: %i[list pointer session], - rule_type_editable: false, - help_text: "Label view for radio button and checkbox items. "\ - "[[http://decko.org/Pointer|more]]", - applies: lambda { |prototype| - prototype.supports_content_options? && - prototype.rule_card(:input_type)&.supports_content_option_view? - } -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/self/content_option_view.rb ~~ diff --git a/set/mod008-list/self/content_options.rb b/set/mod008-list/self/content_options.rb deleted file mode 100644 index ed0178b..0000000 --- a/set/mod008-list/self/content_options.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "ContentOptions" -# -module ContentOptions; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/self/content_options.rb"; end -setting_opts group: :editing, position: 5, - restricted_to_type: %i[list pointer session], - rule_type_editable: true, - help_text: "Value options for [[List]] and [[Pointer]] and cards. "\ - "Can itself be a List or a [[Search]]. "\ - "[[http://decko.org/Pointer|more]]", - applies: lambda { |prototype| - prototype.rule_card(:input_type).supports_content_options? - } -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/self/content_options.rb ~~ diff --git a/set/mod008-list/self/input_options.rb b/set/mod008-list/self/input_options.rb deleted file mode 100644 index 0fb3f0d..0000000 --- a/set/mod008-list/self/input_options.rb +++ /dev/null @@ -1,23 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "InputOptions" -# -module InputOptions; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/self/input_options.rb"; end -include_set Abstract::Pointer - -basket :options -add_to_basket :options, "radio" -add_to_basket :options, "checkbox" -add_to_basket :options, "select" -add_to_basket :options, "multiselect" -add_to_basket :options, "list" -add_to_basket :options, "filtered list" -add_to_basket :options, "autocomplete" - -def content - options.to_pointer_content -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/self/input_options.rb ~~ diff --git a/set/mod008-list/type/link_list.rb b/set/mod008-list/type/link_list.rb deleted file mode 100644 index e7be5d4..0000000 --- a/set/mod008-list/type/link_list.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "LinkList" cards -# -module LinkList; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/type/link_list.rb"; end -include_set Abstract::Pointer - -def raw_item_strings content - reference_chunks(content).map(&:referee_name) -end - -def item_titles default_to_name=true - reference_chunks.map do |chunk| - chunk.options[:title] || (default_to_name ? chunk.referee_name : nil) - end -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def chunk_list - :references - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - :link_list - end - - view :link_list_input, cache: :never do - link_list_input - end - - def items_for_input items=nil - items ||= card.item_names context: :raw - items.empty? ? [["", ""]] : items.zip(card.item_titles(false)) - end - - def link_list_input args={} - items = items_for_input args[:item_list] - extra_class = "pointer-link-list-ul" - ul_classes = classy "pointer-list-editor", extra_class - haml :link_list_input, items: items, ul_classes: ul_classes, - options_card: options_card_name - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/type/link_list.rb ~~ diff --git a/set/mod008-list/type/list.rb b/set/mod008-list/type/list.rb deleted file mode 100644 index a244683..0000000 --- a/set/mod008-list/type/list.rb +++ /dev/null @@ -1,25 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "List" cards -# -module List; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/type/list.rb"; end -include_set Abstract::Pointer - -def each_reference_out - item_names.each do |name| - yield(name, Card::Content::Chunk::Link::CODE) - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :view_list do - %i[info_bar bar box closed titled labeled].map do |view| - voo.items[:view] = view - wrap_with :p, [content_tag(:h3, "#{view} items"), render_content] - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/type/list.rb ~~ diff --git a/set/mod008-list/type/nest_list.rb b/set/mod008-list/type/nest_list.rb deleted file mode 100644 index 3546e15..0000000 --- a/set/mod008-list/type/nest_list.rb +++ /dev/null @@ -1,55 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "NestList" cards -# -module NestList; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/type/nest_list.rb"; end -include_set Abstract::Items - -def raw_item_strings content - reference_chunks(content).map(&:referee_raw_name) -end - -def item_options - nest_chunks.map(&:raw_options) -end - -def items_to_content array - items = array.map { |i| standardize_item i }.reject(&:blank?) - self.content = items.join("\n") -end - -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - def chunk_list - :references - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - :nest_list - end - - view :nest_list_input, cache: :never do - nest_list_input - end - - view :input do - _render_hidden_content_field + super() - end - - def items_for_input items=nil - items ||= card.item_names context: :raw - items.empty? ? [["", ""]] : items.zip(card.item_options) - end - - def nest_list_input args={} - items = items_for_input args[:item_list] - extra_class = "_nest-list-ul" - ul_classes = classy "pointer-list-editor", extra_class - haml :nest_list_input, items: items, ul_classes: ul_classes - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/type/nest_list.rb ~~ diff --git a/set/mod008-list/type/pointer.rb b/set/mod008-list/type/pointer.rb deleted file mode 100644 index a5c8e49..0000000 --- a/set/mod008-list/type/pointer.rb +++ /dev/null @@ -1,19 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Pointer" cards -# -module Pointer; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/list/set/type/pointer.rb"; end -include_set Abstract::Pointer - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :view_list do - %i[info_bar bar box closed titled labeled].map do |view| - voo.items[:view] = view - wrap_with :p, [content_tag(:h3, "#{view} items"), render_content] - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/list/set/type/pointer.rb ~~ diff --git a/set/mod009-permissions/abstract/permission.rb b/set/mod009-permissions/abstract/permission.rb deleted file mode 100644 index b156363..0000000 --- a/set/mod009-permissions/abstract/permission.rb +++ /dev/null @@ -1,132 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Permission) -# -module Permission; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/abstract/permission.rb"; end -def standardize_items - super unless content == "_left" -end - -def options_rule_card - Card[:cards_with_account] -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :pointer_core do - wrap_with :div, pointer_items, class: "pointer-list" - end - - view :core, cache: :never do - if card.content == "_left" - core_inherit_content - else - render! :pointer_core - end - end - - view :one_line_content, cache: :never do - render_core items: { view: :link } - end - - view :input do - item_names = inheriting? ? [] : card.item_names - %( - #{_render_hidden_content_field} -
- #{inheritance_checkbox} -
-
Groups
- #{groups item_names} -
- -
-
Individuals
- #{list_input item_list: item_names, extra_css_class: 'perm-indiv-ul'} -
-
- ) - end - - private - - def groups item_names - group_options.map do |option| - checked = !item_names.delete(option.name).nil? - icon = icon_tag "open_in_new", "link-muted" - option_link = link_to_card option.name, icon, target: "decko_role" - box = check_box_tag "#{option.key}-perm-checkbox", - option.name, checked, class: "perm-checkbox-button" - <<-HTML -
- -
- HTML - end * "\n" - end - - def group_options - Auth.as_bot do - Card.search({ type_id: RoleID, sort: "name" }, "roles by name") - end - end - - def inheritable? - @inheritable ||= - begin - set_name = card.name.trunk_name - set_card = Card.fetch(set_name) - not_set = set_card && set_card.type_id != SetID - not_set ? false : set_card.inheritable? - end - end - - def inheriting? - @inheriting ||= inheritable? && card.content == "_left" - end - - def inheritance_checkbox - return unless inheritable? - - <<-HTML -
- #{check_box_tag 'inherit', 'inherit', inheriting?} - -
- HTML - end - - def core_inherit_content - text = if in_context_of_self_set? - core_inherit_for_content_for_self_set - else - "Inherit from left card" - end - %(#{text}) - end - - def in_context_of_self_set? - return false unless @set_context - - @set_context.to_name.tag_name.key == Card[:self].key - end - - def core_inherit_for_content_for_self_set - task = card.tag.codename - ancestor = Card[@set_context.trunk_name.trunk_name] - links = ancestor.who_can(task).map do |card_id| - link_to_card card_id, nil, target: args[:target] - end * ", " - "Inherit ( #{links} )" - rescue StandardError - "Inherit" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/abstract/permission.rb ~~ diff --git a/set/mod009-permissions/all/permissions.rb b/set/mod009-permissions/all/permissions.rb deleted file mode 100644 index c349439..0000000 --- a/set/mod009-permissions/all/permissions.rb +++ /dev/null @@ -1,240 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Permissions) -# -module Permissions; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/all/permissions.rb"; end -module ClassMethods - def repair_all_permissions - Card.where("(read_rule_class is null or read_rule_id is null) and trash is false") - .each do |broken_card| - broken_card.include_set_modules - broken_card.repair_permissions! - end - end -end - -def repair_permissions! - rule_id, rule_class = permission_rule_id_and_class :read - update_columns read_rule_id: rule_id, read_rule_class: rule_class -end - -# ok? and ok! are public facing methods to approve one action at a time -# -# fetching: if the optional :trait parameter is supplied, it is passed -# to fetch and the test is perfomed on the fetched card, therefore: -# -# trait: :account would fetch this card plus a tag codenamed :account -# trait: :roles, new: {} would initialize a new card with default ({}) -# options. - -def ok? action - @ok ||= {} - aok = @ok[Auth.as_id] ||= {} - if (cached = aok[action]) - cached - else - aok[action] = send "ok_to_#{action}" - end -end - -def ok! action - raise Card::Error::PermissionDenied, self unless ok? action -end - -def who_can action - permission_rule_card(action).item_cards.map(&:id) -end - -def anyone_can? action - who_can(action).include? AnyoneID -end - -def direct_rule_card action - direct_rule_id = rule_card_id action - require_permission_rule! direct_rule_id, action - Card.quick_fetch direct_rule_id -end - -def permission_rule_id action - if compound? && rule(action).match?(/^\[?\[?_left\]?\]?$/) - left_permission_rule_id action - else - rule_card_id(action) - end -end - -def permission_rule_id_and_class action - [permission_rule_id(action), direct_rule_card(action).rule_class_name] -end - -def left_permission_rule_id action - lcard = left_or_new(skip_virtual: true, skip_modules: true) - action = :update if action == :create && lcard.real? && lcard.action != :create - lcard.permission_rule_id action -end - -def permission_rule_card action - Card.fetch permission_rule_id(action) -end - -def require_permission_rule! rule_id, action - return if rule_id - - # RULE missing. should not be possible. - # generalize this to handling of all required rules - errors.add :permission_denied, - t(:permission_error_no_action_rule, action: action, name: name) - raise Card::Error::PermissionDenied, self -end - -def rule_class_name - trunk.type_id == SetID ? name.trunk_name.tag : nil -end - -def you_cant what - "You don't have permission to #{what}" -end - -def deny_because why - @permission_errors << why if @permission_errors - false -end - -def permitted? action - return false if Card.config.read_only # :read does not call #permit - return true if Auth.always_ok? - - Auth.as_card.among? who_can(action) -end - -def permit action, verb=nil - # not called by ok_to_read - if Card.config.read_only - deny_because "Currently in read-only mode" - return false - end - - return true if permitted? action - - verb ||= action.to_s - deny_because you_cant("#{verb} #{name.present? ? name : 'this'}") -end - -def ok_to_create - return false unless permit :create - return true if simple? - - %i[left right].find { |side| !ok_to_create_side side } ? false : true -end - -def ok_to_create_side side - # left is supercard; create permissions will get checked there. - return true if side == :left && superleft - - part_card = send side, new: {} - # if no card, there must be other errors - return true unless part_card&.new_card? && !part_card.ok?(:create) - - deny_because you_cant("create #{part_card.name}") - false -end - -def ok_to_read - return true if Auth.always_ok? - - self.read_rule_id ||= permission_rule_id :read - return true if Auth.as_card.read_rules_hash[read_rule_id] - - deny_because you_cant "read this" -end - -def ok_to_update - return false unless permit(:update) - return true unless type_id_changed? && !permitted?(:create) - - deny_because you_cant("change to this type (need create permission)") -end - -def ok_to_delete - permit :delete -end - -# don't know why we introduced this -# but we have to preserve read rules to make -# delete acts visible in recent changes -pk -# event :clear_read_rule, :store, on: :delete do -# self.read_rule_id = self.read_rule_class = nil -# end - -event :set_read_rule, :store, on: :save, changed: %i[type_id name] do - read_rule_id, read_rule_class = permission_rule_id_and_class(:read) - self.read_rule_id = read_rule_id - self.read_rule_class = read_rule_class -end - -event :set_field_read_rules, after: :set_read_rule, on: :update, changed: :type_id do - each_field_as_bot(&:update_read_rule) -end - -def update_field_read_rules - return unless type_id_changed? || read_rule_id_changed? - - each_field_as_bot do |field| - field.update_read_rule if field.rule(:read) == "_left" - end -end - -def each_field_as_bot &block - # find all cards with me as trunk and update their read_rule - # (because of *type plus right) - # skip if name is updated because will already be resaved - Auth.as_bot do - fields.each(&block) - end -end - -def without_timestamps - Card.record_timestamps = false - yield -ensure - Card.record_timestamps = true -end - -event :update_read_rule do - without_timestamps do - reset_patterns # why is this needed? - rcard_id, rclass = permission_rule_id_and_class :read - # these two are just to make sure vals are correct on current object - self.read_rule_id = rcard_id - self.read_rule_class = rclass - Card.where(id: id).update_all read_rule_id: rcard_id, read_rule_class: rclass - expire :hard - update_field_read_rules - end -end - -def add_to_read_rule_update_queue updates - @read_rule_update_queue = Array.wrap(@read_rule_update_queue).concat updates -end - -event :check_permissions, :validate do - track_permission_errors do - ok? action_for_permission_check - end -end - -def action_for_permission_check - commenting? ? :update : action -end - -def track_permission_errors - @permission_errors = [] - result = yield - @permission_errors.each { |msg| errors.add :permission_denied, msg } - @permission_errors = nil - result -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/all/permissions.rb ~~ diff --git a/set/mod009-permissions/all/update_read_rules.rb b/set/mod009-permissions/all/update_read_rules.rb deleted file mode 100644 index 6605863..0000000 --- a/set/mod009-permissions/all/update_read_rules.rb +++ /dev/null @@ -1,20 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (UpdateReadRules) -# -# FIXME: the following don't really belong here, but they have to come after -module UpdateReadRules; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/all/update_read_rules.rb"; end -# the reference stuff. we need to organize a bit! - -event :update_rule_cache, :finalize, when: :rule? do - Card::Rule.clear_rule_cache -end - -event :expire_related, :finalize do - reset_patterns - structuree_names.each { |name| Director.expirees << name } if is_structure? -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/all/update_read_rules.rb ~~ diff --git a/set/mod009-permissions/right/create.rb b/set/mod009-permissions/right/create.rb deleted file mode 100644 index 9f2f325..0000000 --- a/set/mod009-permissions/right/create.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Create" cards -# -module Create; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/right/create.rb"; end -include_set Abstract::Permission -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/right/create.rb ~~ diff --git a/set/mod009-permissions/right/delete.rb b/set/mod009-permissions/right/delete.rb deleted file mode 100644 index 9b5c854..0000000 --- a/set/mod009-permissions/right/delete.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Delete" cards -# -module Delete; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/right/delete.rb"; end -include_set Abstract::Permission -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/right/delete.rb ~~ diff --git a/set/mod009-permissions/right/read.rb b/set/mod009-permissions/right/read.rb deleted file mode 100644 index 2e90bbb..0000000 --- a/set/mod009-permissions/right/read.rb +++ /dev/null @@ -1,86 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Read" cards -# -module Read; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/right/read.rb"; end -include Abstract::Permission - -format :html do include Abstract::Permission::HtmlFormat end - -event :cascade_read_rule, :finalize, after: :update_rule_cache, when: :rule? do - return unless name_is_changing? || trash_is_changing? - - update_read_ruled_cards -end - -def update_read_ruled_cards - Card::Rule.clear_read_rule_cache - Card.cache.reset # maybe be more surgical, just Auth.user related - expire # probably shouldn't be necessary, - # but was sometimes getting cached version when card should be in the - # trash. could be related to other bugs? - - processed = update_read_rules_of_set_members - update_cards_with_read_rule_id processed unless new? -end - -def update_read_rules_of_set_members - return unless rule_pattern_index - - each_member do |member, processed| - processed << member.key - member.update_read_rule unless member_has_overriding_rule?(member) - end -end - -def member_has_overriding_rule? member - pattern_index(Card.fetch_id(member.read_rule_class)) < rule_pattern_index -end - -# cards with this card as a read_rule_id -# These may include cards that are no longer set members if the card was renamed -# (edge case) -def update_cards_with_read_rule_id processed - processed ||= ::Set.new - Card::Auth.as_bot do - Card.search(read_rule_id: id) do |card| - card.update_read_rule unless processed.include?(card.key) - end - end -end - -def each_member &block - Auth.as_bot do - all_members.each_with_object(::Set.new, &block) - end -end - -def all_members - rule_set.item_cards limit: 0 -end - -def rule_pattern_index - return if trash - - @rule_pattern_index ||= pattern_index rule_set&.tag&.id -end - -def pattern_index pattern_id - pattern_ids.index(pattern_id) || invalid_pattern_id(pattern_id) -end - -def pattern_ids - @pattern_ids ||= set_patterns.map(&:pattern_id) -end - -def invalid_pattern_id pattern_id - Rails.logger.info "invalid pattern id for read rule: #{pattern_id}" -end - -event :process_read_rule_update_queue, :finalize do - left&.update_read_rule -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/right/read.rb ~~ diff --git a/set/mod009-permissions/right/update.rb b/set/mod009-permissions/right/update.rb deleted file mode 100644 index cbb8adf..0000000 --- a/set/mod009-permissions/right/update.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Update" cards -# -module Update; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/right/update.rb"; end -include_set Abstract::Permission -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/right/update.rb ~~ diff --git a/set/mod009-permissions/self/create.rb b/set/mod009-permissions/self/create.rb deleted file mode 100644 index 4284558..0000000 --- a/set/mod009-permissions/self/create.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Create" -# -module Create; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/self/create.rb"; end -setting_opts group: :permission, position: 1, rule_type_editable: false, - short_help_text: "who can create cards", - help_text: "Who can create new cards" -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/self/create.rb ~~ diff --git a/set/mod009-permissions/self/delete.rb b/set/mod009-permissions/self/delete.rb deleted file mode 100644 index fa78e1d..0000000 --- a/set/mod009-permissions/self/delete.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Delete" -# -module Delete; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/self/delete.rb"; end -setting_opts group: :permission, position: 4, rule_type_editable: false, - short_help_text: "who can delete cards", - help_text: "Who can delete cards" -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/self/delete.rb ~~ diff --git a/set/mod009-permissions/self/read.rb b/set/mod009-permissions/self/read.rb deleted file mode 100644 index 37368e6..0000000 --- a/set/mod009-permissions/self/read.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Read" -# -module Read; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/self/read.rb"; end -setting_opts group: :permission, position: 2, rule_type_editable: false, - short_help_text: "who can view cards", - help_text: "Who can view cards in the [[set]]." -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/self/read.rb ~~ diff --git a/set/mod009-permissions/self/update.rb b/set/mod009-permissions/self/update.rb deleted file mode 100644 index bf7a3f2..0000000 --- a/set/mod009-permissions/self/update.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Update" -# -module Update; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/permissions/set/self/update.rb"; end -setting_opts group: :permission, position: 3, rule_type_editable: false, - short_help_text: "who can update cards", - help_text: "Who can update cards" -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/permissions/set/self/update.rb ~~ diff --git a/set/mod010-account/abstract/account_field.rb b/set/mod010-account/abstract/account_field.rb deleted file mode 100644 index ed736c9..0000000 --- a/set/mod010-account/abstract/account_field.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (AccountField) -# -module AccountField; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/abstract/account_field.rb"; end -delegate :accounted, to: :account_card - -def account_card - left -end - -# allow account owner to update account field content -def ok_to_update - return true if own_account? && !name_changed? && !type_id_changed? - - super -end - -# force inherit permission on create -# (cannot be done with rule, because sets are not addressable) -def permission_rule_id action - if action == :create - left_permission_rule_id action - else - super - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/abstract/account_field.rb ~~ diff --git a/set/mod010-account/abstract/accountable.rb b/set/mod010-account/abstract/accountable.rb deleted file mode 100644 index d80854d..0000000 --- a/set/mod010-account/abstract/accountable.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Accountable) -# -module Accountable; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/abstract/accountable.rb"; end -def account - fetch :account, new: {} -end - -def default_account_status - "active" -end - -def current_account? - id && Auth.current_id == id -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def default_bridge_tab - card.current_account? ? :account_tab : super - end - - view :account_tab do - bridge_pill_sections "Account" do - [["Settings", account_details_items], - ["Content", account_content_items]] - end - end - - def show_account_tab? - card.account.real? - end - - def account_formgroups - Auth.as_bot do - subformat(card.account)._render :content_formgroups, structure: true - end - end - - def account_details_items - [ - ["Email and Password", :account, - { path: { slot: { hide: %i[help_link bridge_link] } } }], - ["Roles", :roles, - { path: { view: :content_with_edit_button } }], - ["Notifications", :follow], - ["API", :account, - { path: { view: :api_key, - items: { view: :content }, - slot: { hide: %i[help_link bridge_link] } } }] - ] - end - - def account_content_items - [["Created", :created], - ["Edited", :edited]] - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/abstract/accountable.rb ~~ diff --git a/set/mod010-account/all/account.rb b/set/mod010-account/all/account.rb deleted file mode 100644 index dbccece..0000000 --- a/set/mod010-account/all/account.rb +++ /dev/null @@ -1,115 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Account) -# -module Account; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/all/account.rb"; end -module ClassMethods - def default_accounted_type_id - UserID - end -end - -def account - fetch :account -end - -def parties - @parties ||= (all_enabled_roles << id).flatten.reject(&:blank?) -end - -def among? ok_ids - ok_ids.any? do |ok_id| - ok_id == AnyoneID || - (ok_id == AnyoneWithRoleID && all_enabled_roles.size > 1) || - parties.member?(ok_id) - end -end - -def own_account? - # card is +*account card of signed_in user. - name.part_names[0].key == Auth.as_card.key && - name.part_names[1].key == Card[:account].key -end - -def read_rules - @read_rules ||= fetch_read_rules -end - -def read_rules_hash - @read_rules_hash ||= read_rules.each_with_object({}) { |id, h| h[id] = true } -end - -def fetch_read_rules - return [] if id == WagnBotID # always_ok, so not needed - - ([AnyoneID] + parties).each_with_object([]) do |party_id, rule_ids| - next unless (cache = Card::Rule.read_rule_cache[party_id]) - - rule_ids.concat cache - end -end - -def clear_roles - @parties = @all_roles = @all_active_roles = @read_rules = nil -end - -def with_clear_roles - a = @parties - b = @all_roles - c = @all_active_roles - d = @read_rules - yield -ensure - @parties = a - @all_roles = b - @all_active_roles = c - @read_rules = d -end - -def all_enabled_roles - @all_active_roles ||= (id == AnonymousID ? [] : enabled_role_ids) -end - -def all_roles - @all_roles ||= (id == AnonymousID ? [] : fetch_roles) -end - -def enabled_role_ids - with_enabled_roles do |enabled| - enabled.virtual? ? enabled.item_ids : fetch_roles - end -end - -def with_enabled_roles - Auth.as_bot do - Card::Codename.exists?(:enabled_roles) ? yield(enabled_roles_card) : fetch_roles - end -end - -def enabled_roles_card - fetch :enabled_roles, eager_cache: true, new: { type_id: SessionID } -end - -def fetch_roles - [AnyoneSignedInID] + role_ids_from_roles_trait -end - -def role_ids_from_roles_trait - Auth.as_bot do - role_trait = fetch :roles - role_trait ? role_trait.item_ids : [] - end -end - -event :generate_token do - Digest::SHA1.hexdigest "--#{Time.zone.now.to_f}--#{rand 10}--" -end - -event :set_stamper, :prepare_to_validate do - self.updater_id = Auth.current_id - self.creator_id = updater_id if new_card? -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/all/account.rb ~~ diff --git a/set/mod010-account/right/account.rb b/set/mod010-account/right/account.rb deleted file mode 100644 index b64edd5..0000000 --- a/set/mod010-account/right/account.rb +++ /dev/null @@ -1,62 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Account" cards -# -# -*- encoding : utf-8 -*- -module Account; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/account.rb"; end - -card_accessor :email -card_accessor :password -card_accessor :salt -card_accessor :status - -require_field :email - -def accounted - left -end - -def accounted_id - left_id -end - -def ok_to_read - own_account? || super -end - -# allow account owner to update account field content -def ok_to_update - return true if own_account? && !name_changed? && !type_id_changed? - - super -end - -def changes_visible? act - act.actions_affecting(act.card).each do |action| - return true if action.card.ok? :read - end - false -end - -def send_account_email email_template - ecard = Card[email_template] - unless ecard&.type_id == EmailTemplateID - raise Card::Error, "invalid email template: #{email_template}" - end - - ecard.deliver self, to: email -end - -def method_missing method, *args - return super unless args.empty? && (matches = method.match(/^(?.*)\?$/)) - - status == matches[:status] -end - -def respond_to_missing? method, _include_private=false - method.match?(/\?$/) ? true : super -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/account.rb ~~ diff --git a/set/mod010-account/right/account/events.rb b/set/mod010-account/right/account/events.rb deleted file mode 100644 index a79a166..0000000 --- a/set/mod010-account/right/account/events.rb +++ /dev/null @@ -1,108 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right; module Account; -# Set: All "+Account+Events" cards (Events) -# -#### ON CREATE -module Events; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/account/events.rb"; end - -event :set_default_salt, :prepare_to_validate, on: :create do - add_subfield(:salt).generate -end - -event :set_default_status, :prepare_to_validate, on: :create do - add_subfield :status, content: (accounted&.try(:default_account_status) || "active") -end - -# ON UPDATE - -# reset password emails contain a link to update the +*account card -# and trigger this event -event :reset_password, :prepare_to_validate, on: :update, trigger: :required do - verifying_token :reset_password_success, :reset_password_failure -end - -event :verify_and_activate, :prepare_to_validate, on: :update, trigger: :required do - activatable do - verifying_token :verify_and_activate_success, :verify_and_activate_failure - add_subcard(accounted)&.try :activate_accounted - end -end - -event :password_redirect, :finalize, on: :update, when: :password_redirect? do - success << { id: name, view: "edit" } -end - -# INTEGRATION - -%i[password_reset_email verification_email welcome_email].each do |email| - event "send_#{email}".to_sym, :integrate, trigger: :required do - send_account_email email - end -end - -## EVENT HELPERS - -def activatable - abort :failure, "no field manipulation mid-activation" if subcards.present? - # above is necessary because activation uses super user (Decko Bot), - # so allowing subcards would be unsafe - yield -end - -# NOTE: this only works in the context of an action. -# if run independently, it will not activate an account -event :activate_account do - add_subfield :status, content: "active" - trigger_event! :send_welcome_email -end - -def verifying_token success, failure - requiring_token do |token| - result = Auth::Token.decode token - if result.is_a?(String) - send failure, result - else - send success - end - end -end - -def requiring_token - if !(token = Env.params[:token]) - errors.add :token, "is required" - else - yield token - end -end - -def password_redirect? - Auth.current_id == accounted_id && password.blank? -end - -def verify_and_activate_success - Auth.signin accounted_id - Auth.as_bot # use admin permissions for rest of action - activate_account - success << "" -end - -def verify_and_activate_failure error_message - send_verification_email - errors.add :content, - "Sorry, #{error_message}. Please check your email for a new activation link." -end - -def reset_password_success - Auth.signin accounted_id - success << { id: name, view: :edit } - abort :success -end - -def reset_password_failure error_message - Auth.as_bot { send_password_reset_email } - errors.add :content, t(:account_sorry_email_reset, error_msg: error_message) -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/account/events.rb ~~ diff --git a/set/mod010-account/right/account/views.rb b/set/mod010-account/right/account/views.rb deleted file mode 100644 index e91d255..0000000 --- a/set/mod010-account/right/account/views.rb +++ /dev/null @@ -1,74 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right; module Account; -# Set: All "+Account+Views" cards (Views) -# -module Views; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/account/views.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :verify_url, cache: :never do - raise Error::PermissionDenied unless card.ok?(:create) || card.action - - token_url :verify_and_activate, anonymous: true - end - - view :reset_password_url do - raise Error::PermissionDenied unless card.password_card.ok? :update - - token_url :reset_password - end - - view :token_expiry do - "(#{token_expiry_sentence}" - end - - view :token_days do - Card.config.token_expiry / 1.day - end - - # DEPRECATED - view :verify_days, :token_days - view :reset_password_days, :token_days - - def token_url trigger, extra_payload={} - card_url path(action: :update, - card: { trigger: trigger }, - token: new_token(extra_payload)) - end - - def token_expiry_sentence - "Link will expire in #{render_token_days} days" - end - - def new_token extra_payload - Auth::Token.encode card.accounted_id, extra_payload - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core do - [account_field_nest(:email, "email"), - account_field_nest(:password, "password")] - end - - def account_field_nest field, title - field_nest field, title: title, view: :labeled - # edit: :inline, hide: [:help_link, :bridge_link] - end - - before :content_formgroups do - voo.edit_structure = [[:email, "email"], [:password, "password"]] - end - - view :token_expiry do - "

#{token_expiry_sentence}

" - end -end - -module EmailHtmlFormat; module_parent.send :register_set_format, Card::Format::EmailHtmlFormat, self; extend Card::Set::AbstractFormat - def mail context, fields - super context, fields.reverse_merge(to: card.email) - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/account/views.rb ~~ diff --git a/set/mod010-account/right/email.rb b/set/mod010-account/right/email.rb deleted file mode 100644 index 7bdd3f7..0000000 --- a/set/mod010-account/right/email.rb +++ /dev/null @@ -1,56 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Email" cards -# -# -*- encoding : utf-8 -*- -module Email; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/email.rb"; end - -include_set Abstract::AccountField - -event :validate_email, :validate, on: :save do - return unless content? - - self.content = content.strip - return if content.match?(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) - - errors.add :content, t(:account_error_invalid_address) -end - -event :validate_unique_email, after: :validate_email, on: :save do - if content.present? - Auth.as_bot do - cql = { right_id: EmailID, eq: content, return: :id } - cql[:not] = { id: id } if id - cql_comment = t(:account_search_email_duplicate, content: content) - if Card.search(cql, cql_comment).first - errors.add :content, t(:account_error_not_unique) - end - end - end -end - -event :downcase_email, :prepare_to_validate, on: :save do - return if !content || content == content.downcase - - self.content = content.downcase -end - -def email_required? - !left.system? -end - -def ok_to_read - if own_email? || Auth.always_ok? - true - else - deny_because t(:account_deny_email_restricted) - end -end - -def own_email? - name.part_names[0].key == Auth.as_card.key -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/email.rb ~~ diff --git a/set/mod010-account/right/password.rb b/set/mod010-account/right/password.rb deleted file mode 100644 index f1654c2..0000000 --- a/set/mod010-account/right/password.rb +++ /dev/null @@ -1,61 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Password" cards -# -module Password; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/password.rb"; end -include_set Abstract::AccountField - -def history? - false -end - -def ok_to_read - own_account? || super -end - -event :encrypt_password, :store, - on: :save, changed: :content, - when: proc { !Card::Env[:no_password_encryptions] } do - # no_password_encryptions = hack for import - fix with api for ignoring events - salt = left&.salt - self.content = Auth.encrypt content, salt - - # errors.add :password, 'need a valid salt' - # turns out we have a lot of existing account without a salt. - # not sure when that broke?? -end - -event :validate_password, :validate, on: :save do - return if content.length > 3 - - errors.add :password, t(:account_password_length) -end - -event :validate_password_present, :prepare_to_validate, on: :update do - abort :success if content.blank? -end - -view :raw do - t :account_encrypted -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core, wrap: :em do - render_raw - end - - view :input do - card.content = "" - password_field :content, class: "d0-card-content", autocomplete: autocomplete? - end - - def autocomplete? - return "on" if @parent && @parent.card.name == "*signin+*account" # HACK - - "off" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/password.rb ~~ diff --git a/set/mod010-account/right/roles.rb b/set/mod010-account/right/roles.rb deleted file mode 100644 index 5d5df5e..0000000 --- a/set/mod010-account/right/roles.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Roles" cards -# -module Roles; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/roles.rb"; end -event :validate_permission_to_assign_roles, :validate, on: :save do - return unless (fr = forbidden_roles).present? - - errors.add :permission_denied, - "You don't have permission to assign the role#{'s' if fr.size > 1} "\ - "#{fr.map(&:name).to_sentence}" # LOCALIZE -end - -def forbidden_roles - # restore old roles for permission check - with_old_role_permissions do |new_roles| - new_roles.reject do |card| - Card.fetch(card, "*members").ok? :update - end - end -end - -def with_old_role_permissions - new_roles = item_cards - new_content = content - left.clear_roles - Auth.update_always_cache Card::Auth.as_id, nil - self.content = db_content_before_act - yield new_roles -ensure - self.content = new_content -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/roles.rb ~~ diff --git a/set/mod010-account/right/salt.rb b/set/mod010-account/right/salt.rb deleted file mode 100644 index e775ff0..0000000 --- a/set/mod010-account/right/salt.rb +++ /dev/null @@ -1,22 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Salt" cards -# -module Salt; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/salt.rb"; end -include_set Abstract::AccountField - -def generate - self.content = Digest::SHA1.hexdigest "--#{Time.zone.now}--" -end - -def history? - false -end - -view :raw do - t :account_private_data -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/salt.rb ~~ diff --git a/set/mod010-account/right/status.rb b/set/mod010-account/right/status.rb deleted file mode 100644 index d73f0cb..0000000 --- a/set/mod010-account/right/status.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+Status" cards -# -module Status; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/right/status.rb"; end -include_set Abstract::AccountField -include_set Abstract::Pointer - -def input_type - :radio -end - -def option_names - %w[unapproved unverified active blocked system] -end - -def ok_to_update - if own_account? && !Auth.always_ok? - deny_because you_cant(t(:account_deny_not_change_own_account)) - else - super - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/right/status.rb ~~ diff --git a/set/mod010-account/self/signin.rb b/set/mod010-account/self/signin.rb deleted file mode 100644 index 7d3f378..0000000 --- a/set/mod010-account/self/signin.rb +++ /dev/null @@ -1,222 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "Signin" -# -# The Sign In card manages logging in and out of the site. -# -module Signin; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/self/signin.rb"; end -# /:signin (core view) gives the login ui -# /:signin?view=edit gives the forgot password ui - -# /update/:signin is the login action -# /delete/:signin is the logout action - -# authentication event -event :signin, :validate, on: :update do - email = subfield :email - email &&= email.content - pword = subfield :password - pword &&= pword.content - - authenticate_or_abort email, pword -end - -# abort after successful signin (do not save card) -event :signin_success, after: :signin do - abort :success -end - -event :signout, :validate, on: :delete do - Env.reset_session - Auth.signin AnonymousID - abort :success -end - -# triggered by clicking "Reset my Password", this sends out the verification password -# and aborts (does not sign in) -event :send_reset_password_token, before: :signin, on: :update, trigger: :required do - aborting do - blank_email? ? break : send_reset_password_email_or_fail - end -end - -def email_from_subfield - @email_from_subfield ||= subfield(:email)&.content -end - -def ok_to_read - true -end - -def recaptcha_on? - false -end - -def authenticate_or_abort email, pword - abort_unless email, :email_missing - abort_unless pword, :password_missing - authenticate_and_signin(email, pword) || failed_signin(email) -end - -def authenticate_and_signin email, pword - return unless (account = Auth.authenticate email, pword) - - Auth.signin account.left_id -end - -def failed_signin email - errors.add :signin, signin_error_message(account_for(email)) - abort :failure -end - -def abort_unless value, error_key - abort :failure, t("account_#{error_key}") unless value -end - -def signin_error_message account - t "account_#{signin_error_key account}" -end - -def error_on field, error_key - errors.add field, t("account_#{error_key}") -end - -def account_for email - Auth.find_account_by_email email -end - -def send_reset_password_email_or_fail - if (account = account_for email_from_subfield)&.active? - send_reset_password_email account - else - reset_password_fail account - end -end - -def blank_email? - return false if email_from_subfield.present? - - error_on :email, :error_blank -end - -def send_reset_password_email account - Auth.as_bot { account.send_password_reset_email } -end - -def reset_password_fail account - if account - error_on :account, :error_not_active - else - error_on :email, :error_not_recognized - end -end - -private - -def signin_error_key account - case - when account.nil? then :error_unknown_email - when !account.active? then :error_not_active - else :error_wrong_password - end -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :core, cache: :never do - voo.edit_structure = [signin_field(:email), signin_field(:password)] - with_nest_mode :edit do - card_form :update, recaptcha: :off, success: signin_success do - [ - _render_content_formgroups, - _render_signin_buttons - ] - end - end - end - - view :open do - voo.show :help - voo.hide :menu - super() - end - - # FIXME: need a generic solution for this - view :title do - voo.title ||= t(:account_sign_in_title) - super() - end - - view :open_content do - # annoying step designed to avoid table of contents. sigh - _render_core - end - - view :one_line_content do - "" - end - - view :reset_password_success do - # 'Check your email for a link to reset your password' - frame { t :account_check_email } - end - - view :signin_buttons do - button_formgroup do - [signin_button, signup_link, reset_password_link] - end - end - - # FORGOT PASSWORD - view :edit do - reset_password_voo - Auth.as_bot { super() } - end - - def reset_password_voo - voo.title ||= t :account_forgot_password - voo.edit_structure = [signin_field(:email)] - voo.hide :help - end - - view :edit_buttons do - button_tag t(:account_reset_my_password), - situation: "primary", class: "_close-modal-on-success" - end - - def signin_success - { redirect: true, mark: (Env.interrupted_action || "*previous") } - end - - def signin_button - button_tag t(:account_sign_in), situation: "primary" - end - - def signup_link - subformat(Card[:account_links]).render! :sign_up, title: t(:account_or_sign_up) - end - - def reset_password_link - link = link_to_view :edit, t(:account_reset_password), - path: { slot: { hide: :bridge_link } } - # FIXME: inline styling - raw("
#{link}
") - end - - def edit_view_hidden - hidden_tags card: { trigger: :send_reset_password_token } - end - - def edit_success - { view: :reset_password_success } - end - - def signin_field name - nest_name = "".to_name.trait(name) - [nest_name, { title: name.to_s, view: "titled", - nest_name: nest_name, skip_perms: true }] - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/self/signin.rb ~~ diff --git a/set/mod010-account/type/role.rb b/set/mod010-account/type/role.rb deleted file mode 100644 index fa9ea50..0000000 --- a/set/mod010-account/type/role.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Role" cards -# -module Role; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/type/role.rb"; end -def disabled? - Auth.current&.fetch(:disabled_roles)&.item_ids&.include? id -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :link_with_checkbox, cache: :never do - role_checkbox - end - - def role_checkbox - name = card.disabled? ? "add_item" : "drop_item" - subformat(Auth.current.field(:disabled_roles, new: {})).card_form :update do - [check_box_tag(name, card.id, !card.disabled?, class: "_edit-item"), - render_link] - end - end - - def related_by_content_items - super.unshift ["members", :members] - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/type/role.rb ~~ diff --git a/set/mod010-account/type/signup.rb b/set/mod010-account/type/signup.rb deleted file mode 100644 index bf0ad05..0000000 --- a/set/mod010-account/type/signup.rb +++ /dev/null @@ -1,63 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Signup" cards -# -module Signup; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/type/signup.rb"; end -include_set Abstract::Accountable - -require_field :account - -def default_account_status - can_approve? ? "unverified" : "unapproved" -end - -def can_approve? - Card.new(type_id: Card.default_accounted_type_id).ok? :create -end - -def activate_accounted - self.type_id = Card.default_accounted_type_id -end - -event :auto_approve_with_verification, :validate, on: :create, when: :can_approve? do - request_verification -end - -event :approve_with_verification, :validate, on: :update, trigger: :required do - approvable { request_verification } -end - -event :approve_without_verification, :validate, on: :update, trigger: :required do - # TODO: if validated here, add trigger and activate in storage phase - approvable do - activate_accounted - account_subfield.activate_account - end -end - -event :act_as_current_for_integrate_stage, :integrate, on: :create do - # needs justification! - Auth.current_id = id -end - -def account_subfield - subfield(:account) || add_subfield(:account) -end - -def request_verification - acct = account_subfield - acct.add_subfield :status, content: "unverified" - acct.trigger_event! :send_verification_email -end - -def approvable - if can_approve? - yield - else - abort :failure, "illegal approval" # raise permission denied? - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/type/signup.rb ~~ diff --git a/set/mod010-account/type/signup/views.rb b/set/mod010-account/type/signup/views.rb deleted file mode 100644 index b9bc843..0000000 --- a/set/mod010-account/type/signup/views.rb +++ /dev/null @@ -1,107 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type; module Signup; -# Set: All "Signup+Views" cards (Views) -# -module Views; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/type/signup/views.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def invitation? - Auth.signed_in? && card.can_approve? - end - - view :new do - voo.title = invitation? ? t(:account_invite) : t(:account_sign_up) - super() - end - - view :content_formgroups do - [account_formgroups, (card.structure ? edit_slot : "")].join - end - - view :new_buttons do - button_formgroup do - [standard_create_button, invite_button].compact - end - end - - def invite_button - return unless invitation? - - button_tag "Send Invitation", situation: "primary" - end - - view :core, template: :haml do - @lines = [signup_line] + account_lines - @body = process_content _render_raw - end - - def signup_line - ["#{safe_name}", - ("was" if invited?), - "signed up on #{format_date card.created_at}"].compact.join " " - end - - def invited? - !self_signup? - end - - def self_signup? - card.creator_id == AnonymousID - end - - def account_lines - if card.account - verification_lines - else - [t(:account_missing_account)] - end - end - - def verification_lines - [verification_sent_line, verification_link_line].compact - end - - def verification_sent_line - account = card.account - return unless account.email_card.ok?(:read) - - "A verification email has been sent to #{account.email}" - end - - def verification_link_line - links = verification_links - return if links.empty? - - links.join " " - end - - def verification_links - [approve_with_token_link, approve_without_token_link, deny_link].compact - end - - def approve_with_token_link - action = card.account.status == "unverified" ? "Resend" : "Send" - approval_link "#{action} verification email", :with - end - - def approve_without_token_link - approval_link "Approve without verification", :without - end - - def approval_link text, with_or_without - return unless card.can_approve? - - link_to_card card, text, - path: { action: :update, - card: { trigger: "approve_#{with_or_without}_verification" } } - end - - def deny_link - return unless card.ok? :delete - - link_to_card card, "Deny and delete", path: { action: :delete } - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/type/signup/views.rb ~~ diff --git a/set/mod010-account/type/user.rb b/set/mod010-account/type/user.rb deleted file mode 100644 index 94b5d0b..0000000 --- a/set/mod010-account/type/user.rb +++ /dev/null @@ -1,76 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "User" cards -# -module User; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/type/user.rb"; end -include_set Abstract::Accountable - -attr_accessor :email - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :setup, unknown: true, perms: ->(_fmt) { Auth.needs_setup? } do - with_nest_mode :edit do - voo.title = "Your deck is ready to go!" # LOCALIZE - voo.show! :help - voo.hide! :menu - voo.help = haml :setup_help - Auth.as_bot { setup_form } - end - end - - def setup_form - frame_and_form :create do - [ - setup_hidden_fields, - _render_name_formgroup, - account_formgroups, - setup_form_buttons - ] - end - end - - def setup_form_buttons - button_formgroup { setup_button } - end - - def setup_button - submit_button text: "Set up", disable_with: "Setting up" - end - - def setup_hidden_fields - hidden_tags( - setup: true, - success: { redirect: true, mark: path(mark: "") }, - "card[type_id]" => Card.default_accounted_type_id - ) - end -end - -def setup? - Card::Env.params[:setup] -end - -event :setup_as_bot, before: :check_permissions, on: :create, when: :setup? do - abort :failure unless Auth.needs_setup? - Auth.as_bot - # we need bot authority to set the initial administrator roles - # this is granted and inspected here as a separate event for - # flexibility and security when configuring initial setups -end - -event :setup_first_user, :prepare_to_store, on: :create, when: :setup? do - add_subcard "signup alert email+*to", content: name - add_subfield :roles, content: roles_for_first_user -end - -def roles_for_first_user - %i[help_desk shark administrator].map(&:cardname) -end - -event :signin_after_setup, :integrate, on: :create, when: :setup? do - Auth.signin id -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/type/user.rb ~~ diff --git a/set/mod010-account/type_plus_right/user/email.rb b/set/mod010-account/type_plus_right/user/email.rb deleted file mode 100644 index cf8ceaf..0000000 --- a/set/mod010-account/type_plus_right/user/email.rb +++ /dev/null @@ -1,22 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class TypePlusRight; module User; -# Set: All "+Email" cards on "User" cards -# -# supports legacy references to +*email -module Email; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/account/set/type_plus_right/user/email.rb"; end -# (standard representation is now +*account+*email) -view :raw do - card.content_email || card.account_email || "" -end - -def content_email - content if real? -end - -def account_email - left&.account&.email -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/account/set/type_plus_right/user/email.rb ~~ diff --git a/set/mod011-edit/all/bridge.rb b/set/mod011-edit/all/bridge.rb deleted file mode 100644 index 4e8c31e..0000000 --- a/set/mod011-edit/all/bridge.rb +++ /dev/null @@ -1,73 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Bridge) -# -module Bridge; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge.rb"; end -BRIDGE_TABS = { "Account" => :account_tab, - "Guide" => :guide_tab, - "Engage" => :engage_tab, - "History" => :history_tab, - "Related" => :related_tab, - "Rules" => :rules_tab }.freeze - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - wrapper :bridge do - class_up "modal-dialog", "no-gaps" - voo.hide! :modal_footer - wrap_with_modal size: :full, title: bridge_breadcrumbs do - haml :bridge - end - end - - def bridge_tabs - wrap do - tabs(visible_bridge_tabs, bridge_tab, load: :lazy) { _render bridge_tab } - end - end - - def bridge_tab - @bridge_tab ||= bridge_param :tab - end - - def bridge_param key - params.dig(:bridge, key)&.to_sym || try("default_bridge_#{key}") - end - - def bridge_breadcrumbs - <<-HTML.strip_heredoc - - HTML - end - - def bridge_link_opts opts={} - opts[:"data-slot-selector"] = bridge_slot_selector - opts[:remote] = true - add_class opts, "slotter" - opts.bury :path, :layout, :overlay - opts[:path][:view] ||= :content - opts - end - - def bridge_slot_selector - ".bridge-main > .overlay-container > .card-slot._bottomlay-slot," \ - ".bridge-main > ._overlay-container-placeholder > .card-slot" - end - - def default_bridge_tab - show_guide_tab? ? :guide_tab : :engage_tab - end - - def breadcrumb_data title, html_class=nil - html_class ||= title.underscore - { "data-breadcrumb": title, "data-breadcrumb-class": html_class } - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge.rb ~~ diff --git a/set/mod011-edit/all/bridge/bridge_pills.rb b/set/mod011-edit/all/bridge/bridge_pills.rb deleted file mode 100644 index 1a3a62f..0000000 --- a/set/mod011-edit/all/bridge/bridge_pills.rb +++ /dev/null @@ -1,56 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module Bridge; -# Set: All cards (Bridge, BridgePills) -# -module BridgePills; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/bridge_pills.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - BRIDGE_PILL_UL_CLASSES = - "nav nav-pills _auto-single-select bridge-pills flex-column".freeze - - BRIDGE_PILL_LI_CLASSES = "nav-item".freeze - - def bridge_pills items - list_tag class: BRIDGE_PILL_UL_CLASSES, items: { class: BRIDGE_PILL_LI_CLASSES } do - items - end - end - - def bridge_pill_items data, breadcrumb - data.map do |text, field, extra_opts| - opts = bridge_pill_item_opts breadcrumb, extra_opts, text - mark = opts.delete(:mark) == :absolute ? field : [card, field] - link_to_card mark, text, opts - end - end - - def bridge_pill_item_opts breadcrumb, extra_opts, text - opts = bridge_link_opts.merge("data-toggle": "pill") - opts.merge! breadcrumb_data(breadcrumb) - - if extra_opts - classes = extra_opts.delete :class - add_class opts, classes if classes - opts.deep_merge! extra_opts - end - opts["data-cy"] = "#{text.to_name.key}-pill" - add_class opts, "nav-link" - opts - end - - def bridge_pill_sections tab_name - wrap_with :ul, class: BRIDGE_PILL_UL_CLASSES do - yield.map { |args| bridge_pill_section(tab_name, *args) } - end - end - - def bridge_pill_section tab_name, title, items - wrap_with(:h6, title, class: "ml-1 mt-3") + - wrap_each_with(:li, class: BRIDGE_PILL_LI_CLASSES) do - bridge_pill_items(items, tab_name) - end.html_safe - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/bridge_pills.rb ~~ diff --git a/set/mod011-edit/all/bridge/follow_section.rb b/set/mod011-edit/all/bridge/follow_section.rb deleted file mode 100644 index 625401d..0000000 --- a/set/mod011-edit/all/bridge/follow_section.rb +++ /dev/null @@ -1,46 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module Bridge; -# Set: All cards (Bridge, FollowSection) -# -module FollowSection; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/follow_section.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def follow_section - return unless show_follow? - - wrap_with :div, class: "mb-3" do - [follow_button_group, followers_bridge_link, follow_overview_button] - end - end - - def follow_button_group - wrap_with :div, class: "btn-group btn-group-sm follow-btn-group" do - [follow_button, follow_advanced] - end - end - - def follow_overview_button - link_to_card [Auth.current, :follow], "all followed cards", - bridge_link_opts(class: "btn btn-sm btn-secondary", - "data-cy": "follow-overview") - end - - def follow_advanced - opts = bridge_link_opts(class: "btn btn-sm btn-primary", - path: { view: :overlay_rule }, - "data-cy": "follow-advanced") - opts[:path].delete :layout - link_to_card card.follow_rule_card(Auth.current.name, new: {}), - icon_tag("more_horiz"), opts - end - - def followers_bridge_link - cnt = card.followers_count - link_to_card card.name.field(:followers), "#{cnt} follower#{'s' unless cnt == 1}", - bridge_link_opts(class: "btn btn-sm ml-2 btn-secondary slotter", - remote: true, "data-cy": "followers") - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/follow_section.rb ~~ diff --git a/set/mod011-edit/all/bridge/related_section.rb b/set/mod011-edit/all/bridge/related_section.rb deleted file mode 100644 index ad7e6c0..0000000 --- a/set/mod011-edit/all/bridge/related_section.rb +++ /dev/null @@ -1,43 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module Bridge; -# Set: All cards (Bridge, RelatedSection) -# -module RelatedSection; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/related_section.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - RELATED_ITEMS = - { - "by name" => [["children", :children], - ["mates", :mates]], - # FIXME: optimize, - "by content" => [["links out", :links_to], - ["links in", :linked_to_by], - ["nests", :nests], - ["nested by", :nested_by], - ["references out", :refers_to], - ["references in", :referred_to_by]] - # ["by edit", [["creator", :creator], - # ["editors", :editors], - # ["last edited", :last_edited]]] - }.freeze - - def related_by_name_items - pills = [] - if card.name.compound? - pills += card.name.ancestors.map { |a| [a, a, { mark: :absolute }] } - end - pills += RELATED_ITEMS["by name"] - pills - end - - def related_by_content_items - RELATED_ITEMS["by content"] - end - - def related_by_type_items - [["#{card.type} cards", [card.type, :type, :by_name], { mark: :absolute }]] - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/related_section.rb ~~ diff --git a/set/mod011-edit/all/bridge/tab_views.rb b/set/mod011-edit/all/bridge/tab_views.rb deleted file mode 100644 index 83d1431..0000000 --- a/set/mod011-edit/all/bridge/tab_views.rb +++ /dev/null @@ -1,50 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module Bridge; -# Set: All cards (Bridge, TabViews) -# -module TabViews; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/tab_views.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :engage_tab, wrap: { div: { class: "m-3 mt-4 _engage-tab" } }, cache: :never do - [render_follow_section, discussion_section].compact - end - - view :history_tab, wrap: :slot do - class_up "d0-card-body", "history-slot" - voo.hide :act_legend - acts_bridge_layout card.history_acts - end - - view :related_tab do - bridge_pill_sections "Related" do - %w[name content type].map do |section_name| - ["by #{section_name}", send("related_by_#{section_name}_items")] - end - end - end - - view :rules_tab, unknown: true do - class_up "card-slot", "flex-column" - wrap do - nest current_set_card, view: :bridge_rules_tab - end - end - - view :follow_section, wrap: :slot, cache: :never do - follow_section - end - - view :guide_tab, unknown: true do - render_guide - end - - def discussion_section - return unless show_discussion? - - field_nest(:discussion, view: :titled, title: "Discussion", show: :comment_box, - hide: [:menu]) - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/tab_views.rb ~~ diff --git a/set/mod011-edit/all/bridge/tab_visibility.rb b/set/mod011-edit/all/bridge/tab_visibility.rb deleted file mode 100644 index 1737308..0000000 --- a/set/mod011-edit/all/bridge/tab_visibility.rb +++ /dev/null @@ -1,67 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module Bridge; -# Set: All cards (Bridge, TabVisibility) -# -module TabVisibility; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/tab_visibility.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def visible_bridge_tabs - Bridge::BRIDGE_TABS.select do |_title, view| - send "show_#{view}?" - end - end - - private - - def show_engage_tab? - return unless card.real? - - show_follow? || show_discussion? - end - - def show_account_tab? - false - end - - def show_history_tab? - card.real? - end - - def show_related_tab? - card.real? - end - - def show_rules_tab? - true - end - - def show_guide_tab? - guide.present? - end - - def show_discussion? - return unless (d_card = discussion_card) - - d_card.ok? discussion_permission_task(d_card) - end - - def discussion_card? - card.compound? && card.name.tag_name.key == :discussion.cardname.key - end - - def discussion_card - return if card.new_card? || discussion_card? - - card.fetch :discussion, skip_modules: true, new: {} - end - - private - - def discussion_permission_task d_card=nil - d_card ||= discussion_card - d_card.new_card? ? :update : :read - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/bridge/tab_visibility.rb ~~ diff --git a/set/mod011-edit/all/edit_content.rb b/set/mod011-edit/all/edit_content.rb deleted file mode 100644 index ce1745b..0000000 --- a/set/mod011-edit/all/edit_content.rb +++ /dev/null @@ -1,69 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (EditContent) -# -module EditContent; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_content.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :edit_form, wrap: :slot do - voo.show :edit_type_row - with_nest_mode :edit do - edit_form - end - end - - def edit_form - voo.hide :edit_type_row - form_opts = edit_form_opts.reverse_merge success: edit_success - card_form(:update, form_opts) do - [ - edit_view_hidden, - _render_edit_type_row(home_view: :edit_type_row), - # home_view is necessary for cancel to work correctly. - # it seems a little strange to have to think about home_view here, - # but the issue is that something currently has to happen prior to the - # render to get voo.slot_options to have the write home view in - # the slot wrap. Id think this would probably best be handled as an - # option to #wrap that triggers a new heir voo - _render_content_formgroups, - _render_edit_buttons - ] - end - end - - view :edit, perms: :update, unknown: true, cache: :never, - wrap: { modal: { footer: "", - size: :edit_modal_size, - title: :render_title, - menu: :edit_modal_menu } } do - add_name_context - with_nest_mode :edit do - voo.show :help - voo.hide :save_button - wrap true do - [ - frame_help, - _render_edit_form - ] - end - end - end - - def edit_modal_size - :large - end - - def edit_modal_menu - wrap_with_modal_menu do - [close_modal_window, render_bridge_link] - end - end - - def edit_form_opts - # for override - { "data-slot-selector": "modal-origin", "data-slot-error-selector": ".card-slot" } - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_content.rb ~~ diff --git a/set/mod011-edit/all/edit_inline.rb b/set/mod011-edit/all/edit_inline.rb deleted file mode 100644 index f50af49..0000000 --- a/set/mod011-edit/all/edit_inline.rb +++ /dev/null @@ -1,65 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (EditInline) -# -module EditInline; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_inline.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :edit_inline, perms: :update, unknown: true, cache: :never, wrap: :slot do - voo.hide :name_formgroup, :type_formgroup - with_nest_mode :edit do - card_form :update, success: edit_success do - [ - edit_view_hidden, - _render_content_formgroups, - _render_edit_inline_buttons - ] - end - end - end - - view :edit_name_row do - edit_row_fixed_width "Name", card.name, :name_form - end - - view :edit_inline_buttons do - button_formgroup do - wrap_with "div", class: "d-flex" do - [standard_save_button, cancel_in_place_button, delete_button] - end - end - end - - # TODO: better styling for this so that is reusable - # At the moment it is used for the name and type field in the bridge - # (with fixed 50px width for the title column) and - # for password and email for accounts (with fixed 75px width for the title column) - # The view is very similar to labeled but with fixed edit link on the right - # and a fixed width for the labels so that the content column is aligned - # There is also the problem that label and content are not vertically aligned - view :edit_row do - edit_row_fixed_width render_title, render_core, :edit_inline, 75 - end - - def edit_row_fixed_width title, content, edit_view, width=50 - class_up "card-slot", "d-flex" - wrap do - ["", - content, - edit_inline_link(edit_view, align: :right)] - end - end - - def edit_inline_link view=:edit_inline, align: :left - align = align == :left ? "ml-2" : "ml-auto" - link_to_view view, menu_icon, class: "#{align} edit-link", "data-cy": "edit-link" - end - - def cancel_in_place_button args={} - args.reverse_merge! class: "cancel-button btn-sm", href: path - cancel_button args - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_inline.rb ~~ diff --git a/set/mod011-edit/all/edit_name.rb b/set/mod011-edit/all/edit_name.rb deleted file mode 100644 index 70d9d7a..0000000 --- a/set/mod011-edit/all/edit_name.rb +++ /dev/null @@ -1,65 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (EditName) -# -module EditName; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_name.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :edit_name, perms: :update do - frame { name_form } - end - - view :name_form, perms: :update, wrap: :slot, cache: :never do - name_form :edit_name_row - end - - def name_form success_view=nil - card_form({ action: :update, id: card.id }, - { "data-main-success": JSON(redirect: true, view: ""), - "data-update-origin": "true", - class: "_rename-form", - success: edit_name_success(success_view) }) do - [edit_name_hidden_fields, - _render_name_formgroup, - edit_name_confirmation, - edit_name_buttons] - end - end - - def edit_name_success view=nil - success = { name: "_self", redirect: "" } - success[:view] = view if view - success - end - - def edit_name_hidden_fields - hidden_tags old_name: card.name, card: { update_referers: false } - end - - def edit_name_buttons - class_up "button-form-group", "rename-button-form-group" - button_formgroup do - [rename_and_update_button, rename_button, standard_cancel_button] - end - end - - def edit_name_confirmation - alert "warning", false, false, class: "hidden-alert" do - haml :edit_name_confirmation, referer_count: card.references_in.count - end - end - - def rename_and_update_button - submit_button text: t(:core_rename_and_update), - disable_with: t(:core_renaming), - class: "_renamer-updater" - end - - def rename_button - button_tag t(:core_rename), - class: "renamer", data: { disable_with: t(:core_renaming) } - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_name.rb ~~ diff --git a/set/mod011-edit/all/edit_type.rb b/set/mod011-edit/all/edit_type.rb deleted file mode 100644 index 8ee15ed..0000000 --- a/set/mod011-edit/all/edit_type.rb +++ /dev/null @@ -1,129 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (EditType) -# -module EditType; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_type.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :edit_type, cache: :never, perms: :update do - frame do - _render_edit_type_form - end - end - - view :edit_type_form, cache: :never, perms: :update, wrap: :slot do - card_form :update, success: edit_type_success do - [type_formgroup, render_new_buttons] - end - end - - def edit_type_success - { view: :core } - end - - view :edit_type_row do - return _render_bridge_type_formgroup if voo.visible?(:type_form) { false } - - edit_row_fixed_width "Type", link_to_card(card.type), :bridge_type_formgroup - end - - view :bridge_type_formgroup, unknown: true, wrap: :slot do - type_formgroup href: path(mark: card.id, - view: :edit_form, - assign: true, - slot: { show: :type_form }), - class: "live-type-field slotter", - 'data-remote': true, - 'data-slot-selector': ".card-slot.edit_form-view" - end - - view :type_formgroup do - type_formgroup - end - - def type_formgroup args={} - add_class args, "type-field" - wrap_type_formgroup do - type_field args - end - end - - def type_field args={} - @no_current_type = args.delete :no_current_type # just a test artifact? - action_view.select_tag "card[type]", type_field_options, - args.merge("data-select2-id": "#{unique_id}-#{Time.now.to_i}") - end - - private - - def raw_type_options - return @raw_type_options if @raw_type_options - - options = Auth.createable_types - if !@no_current_type && card.real? && !options.include?(card.type_name) - # current type should be an option on existing cards, - # regardless of create perms - options.push(card.type_name).sort! - end - @raw_type_options = ::Set.new options - end - - def wrap_type_formgroup - formgroup "Type", input: "type", class: "type-formgroup", help: false do - output [yield, hidden_field_tag(:assign, true)] - end - end - - def type_field_options - if grouped_types.size == 1 - simple_type_field_options - else - multi_type_field_options - end - end - - def simple_type_field_options - options_for_select grouped_types.flatten[1], current_type_value - end - - def multi_type_field_options - grouped_options_for_select grouped_types, current_type_value - end - - def current_type_value - return if @no_current_type - - @current_type_value ||= card.type_name_or_default - end - - def grouped_types - groups = Hash.new { |h, k| h[k] = [] } - - visible_cardtype_groups.each_pair.with_object(groups) do |(name, items), grps| - if name == "Custom" - custom_grouped_types grps - else - standard_grouped_types grps, name, items - end - end - end - - def custom_grouped_types groups - Auth.createable_types.each do |type| - groups["Custom"] << type unless ::Card::Set::Self::Cardtype::GROUP_MAP[type] - end - end - - def standard_grouped_types groups, name, items - items.each do |i| - groups[name] << i if raw_type_options.include?(i) - end - end - - def visible_cardtype_groups - ::Card::Set::Self::Cardtype::GROUP - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/edit_type.rb ~~ diff --git a/set/mod011-edit/all/editing.rb b/set/mod011-edit/all/editing.rb deleted file mode 100644 index 4f4309a..0000000 --- a/set/mod011-edit/all/editing.rb +++ /dev/null @@ -1,100 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Editing) -# -module Editing; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/editing.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - ###---( TOP_LEVEL (used by menu) NEW / EDIT VIEWS ) - view :bridge, perms: :update, unknown: true, cache: :never, wrap: :bridge do - with_nest_mode :edit do - add_name_context - voo.show :help - wrap true, breadcrumb_data("Editing", "edit") do - bridge_parts - end - end - end - - view :cardboard, :bridge - - def bridge_parts - voo.show! :edit_type_row - - [ - frame_help, - _render_edit_name_row(home_view: :edit_name_row), - # home_view is necessary for cancel to work correctly. - # it seems a little strange to have to think about home_view here, - # but the issue is that something currently has to happen prior to the - # render to get voo.slot_options to have the write home view in - # the slot wrap. I think this would probably best be handled as an - # option to #wrap that triggers a new heir voo - _render_edit_form - ] - end - - def edit_success - # for override - end - - def edit_view_hidden - # for override - end - - view :edit_buttons do - button_formgroup do - wrap_with "div", class: "d-flex" do - [standard_submit_button, edit_cancel_button, delete_button] - end - end - end - - # TODO: add undo functionality - view :just_deleted, unknown: true do - wrap { "#{render_title} deleted" } - end - - view :edit_rules, cache: :never, unknown: true do - nest current_set_card, view: :bridge_rules_tab - end - - view :edit_structure, cache: :never do - return unless card.structure - - nest card.structure_rule_card, view: :edit - # FIXME: this stuff: - # slot: { - # cancel_slot_selector: ".card-slot.related-view", - # cancel_path: card.format.path(view: :edit), hide: :edit_toolbar, - # hidden: { success: { view: :open, "slot[subframe]" => true } } - # } - # } - end - - view :edit_nests, cache: :never do - frame do - with_nest_mode :edit do - multi_card_edit - end - end - end - - # FIXME: - view can recurse. temporarily turned off - # - # view :edit_nest_rules, cache: :never do - # return ""# - # view = args[:rule_view] || :field_related_rules - # frame do - # # with_nest_mode :edit do - # nested_fields.map do |name, _options| - # nest Card.fetch(name.to_name.trait(:self)), - # view: :titled, title: name, rule_view: view, - # hide: :set_label, show: :rule_navbar - # end - # end - # end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/editing.rb ~~ diff --git a/set/mod011-edit/all/editor.rb b/set/mod011-edit/all/editor.rb deleted file mode 100644 index f976726..0000000 --- a/set/mod011-edit/all/editor.rb +++ /dev/null @@ -1,63 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Editor) -# -module Editor; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/editor.rb"; end -Self::InputOptions.add_to_basket :options, "text area" -Self::InputOptions.add_to_basket :options, "text field" - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type - voo.input_type.present? ? voo.input_type : input_type_from_rule - end - - def input_type_from_rule - card.rule(:input_type)&.gsub(/[\[\]]/, "")&.tr(" ", "_") - end - - def input_method input_type - "#{input_type}_input" - end - - # core view of card is input - def input_defined_by_card - with_card input_type do |input_card| - nest input_card, view: :core - end - end - - # move somewhere more accessible? - def with_card mark - card = Card[mark] - yield card if card - rescue Card::Error::CodenameNotFound - nil - end - - view :input, unknown: true do - try(input_method(input_type)) || - input_defined_by_card || - send(input_method(default_input_type)) - end - - def default_input_type - :rich_text - end - - def rich_text_input - send "#{Cardio.config.rich_text_editor || :text_area}_editor_input" - end - - def text_area_input - text_area :content, rows: 5, class: "d0-card-content", - "data-card-type-code": card.type_code - end - - def text_field_input - text_field :content, class: classy("d0-card-content") - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/editor.rb ~~ diff --git a/set/mod011-edit/all/form.rb b/set/mod011-edit/all/form.rb deleted file mode 100644 index fd7a3c9..0000000 --- a/set/mod011-edit/all/form.rb +++ /dev/null @@ -1,257 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Form) -# -module Form; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/form.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - # FIELDSET VIEWS - - # sometimes multiple card formgroups, sometimes just one - view :content_formgroups, cache: :never do - wrap_with :fieldset, edit_slot, class: classy("card-editor", "editor") - end - - view :name_formgroup do - formgroup "Name", input: "name", help: false do - raw name_field - end - end - - # single card content formgroup, labeled with "Content" - view :content_formgroup, unknown: true, cache: :never do - wrap_content_formgroup { content_field } - end - - view :edit_in_form, cache: :never, perms: :update, unknown: true do - reset_form - @in_multi_card_editor = true - edit_slot - end - - view :conflict_tracker, cache: :never, unknown: true do - return unless card&.real? - - card.last_action_id_before_edit = card.last_action_id - hidden_field :last_action_id_before_edit, class: "current_revision_id" - end - - def wrap_content_formgroup &block - formgroup("Content", input: :content, help: false, - class: classy("card-editor"), &block) - end - - def button_formgroup &block - wrap_with :div, class: "form-group #{classy 'button-form-group'}", &block - end - - def name_field - # value needed because otherwise gets wrong value if there are updates - text_field :name, value: card.name, autocomplete: "off" - end - - def content_field - with_nest_mode :normal do - # by changing nest mode to normal, we ensure that editors (eg image - # previews) can render core views. - output [_render_conflict_tracker, _render_input] - end - end - - # SAMPLE editor view for override - # view :input do - # text_area :content, rows: 5, class: "d0-card-content" - # end - - def edit_slot - case - when inline_nests_editor? then _render_core - when multi_card_editor? then multi_card_edit(true) - when in_multi_card_editor? then editor_in_multi_card - else single_card_edit_field - end - end - - # test: render nests within a normal rendering of the card's content? - # (as opposed to a standardized form) - def inline_nests_editor? - voo.input_type == :inline_nests - end - - # test: are we opening a new multi-card form? - def multi_card_editor? - voo.structure || voo.edit_structure || # structure configured in voo - card.structure || # structure in card rule - edit_fields? # list of fields in card rule - end - - # override and return true to optimize - def edit_fields? - edit_fields.present? - end - - # test: are we already within a multi-card form? - def in_multi_card_editor? - @in_multi_card_editor.present? - end - - def single_card_edit_field - if voo.show?(:type_formgroup) || voo.show?(:name_formgroup) - _render_content_formgroup # use formgroup for consistency - else - editor_wrap(:content) { content_field } - end - end - - def editor_in_multi_card - add_junction_class - formgroup render_title, - input: "content", help: true, class: classy("card-editor") do - [content_field, (form.hidden_field(:type_id) if card.new_card?)] - end - end - - def multi_card_edit fields_only=false - field_configs = edit_field_configs fields_only - return structure_link if field_configs.empty? - - field_configs.map do |name, options| - nest name, options || {} - end.join "\n" - end - - def structure_link - # LOCALIZE - structured = link_to_card card.structure_rule_card, "structured" - ""\ - "

Uneditable; content is #{structured} without nests

" - end - - # @param [Hash|Array] fields either an array with field names and/or field - # cards or a hash with the fields as keys and a hash with nest options as - # values - def process_edit_fields fields - fields.map do |field, opts| - field_nest field, opts - end.join "\n" - end - ### - - # If you use subfield cards to render a form for a new card - # then the subfield cards should be created on the new card not the existing - # card that build the form - - def form - @form ||= inherit(:form) || new_form - end - - def new_form - @form_root = true unless parent&.form_root - instantiate_builder(form_prefix, card, {}) - end - - def reset_form - @form = new_form - end - - def form_prefix - case - when explicit_form_prefix then explicit_form_prefix # configured - when simple_form? then "card" # simple form - when parent.card.name == card.name then parent.form_prefix # card nests self - else edit_in_form_prefix - end - end - - def simple_form? - form_root? || !form_root || !parent - end - - def edit_in_form_prefix - "#{parent.form_prefix}[subcards][#{card.name.from form_context.card.name}]" - end - - def explicit_form_prefix - inherit :explicit_form_prefix - end - - def form_context - form_root? || !form_root ? self : parent - end - - def form_root? - @form_root == true - end - - def form_root - return self if @form_root - - parent ? parent.form_root : nil - end - - def card_form action, opts={} - @form_root = true - hidden = hidden_form_tags action, opts - form_for card, card_form_opts(action, opts) do |cform| - @form = cform - hidden + output(yield(cform)) - end - end - - def hidden_form_tags _action, opts - success = opts.delete :success - success_tags success - end - - # @param action [Symbol] :create or :update - # @param opts [Hash] html options - # @option opts [Boolean] :redirect (false) if true form is no "slotter" - def card_form_opts action, opts={} - url, action = card_form_url_and_action action - html_opts = card_form_html_opts action, opts - form_opts = { url: url, html: html_opts } - form_opts[:remote] = true unless html_opts.delete(:redirect) - form_opts - end - - def card_form_html_opts action, opts={} - add_class opts, "card-form" - add_class opts, "slotter" unless opts[:redirect] || opts[:no_slotter] - add_class opts, "autosave" if action == :update - interpret_main_success_opts opts - opts - end - - def interpret_main_success_opts opts - return unless (hash = opts.delete :main_success) - - opts["data-main-success"] = JSON hash - end - - def card_form_url_and_action action - case action - when Symbol then [path(action: action), action] - when Hash then [path(action), action[:action]] - # for when non-action path args are required - else - raise Card::Error, "unsupported #card_form_url action: #{action}" - end - end - - def editor_wrap type=nil, &block - html_class = "editor" - html_class << " #{type}-editor" if type - wrap_with :div, class: html_class, &block - end - - # FIELD VIEWS - - def add_junction_class - return unless card.name.compound? - - class_up "card-editor", "RIGHT-#{card.name.tag_name.safe_key}" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/form.rb ~~ diff --git a/set/mod011-edit/all/form_buttons.rb b/set/mod011-edit/all/form_buttons.rb deleted file mode 100644 index 966dae5..0000000 --- a/set/mod011-edit/all/form_buttons.rb +++ /dev/null @@ -1,82 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (FormButtons) -# -module FormButtons; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/form_buttons.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def standard_submit_button - output [standard_save_button, standard_save_and_close_button] - end - - def standard_save_button opts={} - return if voo&.hide?(:save_button) - - add_class opts, "submit-button btn-sm mr-3 _update-history-pills" - opts[:text] ||= "Save" - opts["data-cy"] = "save" - submit_button opts - end - - # @param opts [Hash] - # @option close [:modal, :overlay] - # - def standard_save_and_close_button opts={} - close = opts.delete(:close) || :modal - text = opts[:text] || "Save and Close" - add_class opts, "submit-button btn-sm mr-3 _close-on-success" - add_class opts, "_update-origin" unless opts[:no_origin_update] - opts.reverse_merge! text: text, "data-cy": "submit-#{close}" - - submit_button opts - end - - def standard_cancel_button args={} - args.reverse_merge! class: "cancel-button ml-4", href: path, "data-cy": "cancel" - cancel_button args - end - - def modal_cancel_button - modal_close_button "Cancel", situation: "secondary", class: "btn-sm cancel-button" - end - - def edit_cancel_button - modal_cancel_button - end - - def new_cancel_button - voo.show?(:cancel_button) && modal_cancel_button - end - - def delete_button opts={} - return unless card.real? - - link_to "Delete", delete_button_opts(opts) - end - - def delete_button_opts opts={} - add_class opts, "slotter btn btn-outline-danger ml-auto btn-sm" - opts["data-confirm"] = delete_confirm opts - opts[:path] = { action: :delete } - opts[:path][:success] = delete_success(opts) - opts[:remote] = true - opts - end - - def delete_confirm opts - opts.delete(:confirm) || "Are you sure you want to delete #{safe_name}?" - end - - def delete_success opts - if opts[:success] - opts.delete :success - elsif main? - { redirect: true, mark: "*previous" } - else - { view: :just_deleted } - end - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/form_buttons.rb ~~ diff --git a/set/mod011-edit/all/form_elements.rb b/set/mod011-edit/all/form_elements.rb deleted file mode 100644 index 8d89293..0000000 --- a/set/mod011-edit/all/form_elements.rb +++ /dev/null @@ -1,81 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (FormElements) -# -module FormElements; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/form_elements.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def success_tags opts - return "" unless opts.present? - - hidden_tags success: opts - end - - # convert hash into a collection of hidden tags - def hidden_tags hash, base=nil - hash ||= {} - hash.inject("") do |result, (key, val)| - new_base = base ? "#{base}[#{key}]" : key - result + process_hidden_value(val, new_base) - end - end - - def process_hidden_value val, base - case val - when Hash - hidden_tags val, base - when Array - base += "[]" - val.map do |v| - hidden_field_tag base, v - end.join - else - hidden_field_tag base, val - end - end - - FIELD_HELPERS = - %w[ - hidden_field color_field date_field datetime_field datetime_local_field - email_field month_field number_field password_field phone_field - range_field search_field telephone_field text_area text_field time_field - url_field week_field file_field label check_box radio_button - ].freeze - - FIELD_HELPERS.each do |method_name| - define_method(method_name) do |*args| - form.send(method_name, *args) - end - end - - def submit_button args={} - text = args.delete(:text) || "Submit" - args.reverse_merge! situation: "primary", data: {} - args[:data][:disable_with] ||= args.delete(:disable_with) || "Submitting" - button_tag text, args - end - - # redirect to *previous if no :href is given - def cancel_button args={} - return unless voo.show? :cancel_button - - text = args.delete(:text) || "Cancel" - add_class args, "btn btn-#{args.delete(:situation) || 'secondary'}" - add_class args, cancel_strategy(args[:redirect], args[:href]) - args[:href] ||= path_to_previous - args["data-remote"] = true - link_to text, args - end - - def cancel_strategy redirect, href - redirect = href.blank? if redirect.nil? - redirect ? "redirecter" : "slotter" - end - - def path_to_previous - path mark: "*previous" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/form_elements.rb ~~ diff --git a/set/mod011-edit/all/formgroup.rb b/set/mod011-edit/all/formgroup.rb deleted file mode 100644 index 93cd0fe..0000000 --- a/set/mod011-edit/all/formgroup.rb +++ /dev/null @@ -1,46 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (Formgroup) -# -module Formgroup; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/formgroup.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - # a formgroup has a label, an input and help text - def formgroup title, opts={}, &block - wrap_with :div, formgroup_div_args(opts[:class]) do - formgroup_body title, opts, &block - end - end - - def formgroup_body title, opts, &block - label = formgroup_label opts[:input], title - editor_body = editor_wrap opts[:input], &block - help_text = formgroup_help_text opts[:help] - "#{label}
#{help_text} #{editor_body}
" - end - - def formgroup_label input, title - return if voo&.hide?(:title) || title.blank? - - label_type = input || :content - form.label label_type, title - end - - def formgroup_div_args html_class - div_args = { class: ["form-group", html_class].compact.join(" ") } - div_args[:card_id] = card.id if card.real? - div_args[:card_name] = h card.name if card.name.present? - div_args - end - - def formgroup_help_text text=nil - return "" if text == false - - class_up "help-text", "help-block" - voo.help = text if voo && text.to_s != "true" - _render_help - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/formgroup.rb ~~ diff --git a/set/mod011-edit/all/new.rb b/set/mod011-edit/all/new.rb deleted file mode 100644 index b228c6b..0000000 --- a/set/mod011-edit/all/new.rb +++ /dev/null @@ -1,195 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (New) -# -module New; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/new.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - delegate :autoname?, to: :card - - view :new, perms: :create, unknown: true, cache: :never do - new_view_frame_and_form new_form_opts - end - - view :new_content_form, wrap: :slot, unknown: true, cache: :never do - with_nest_mode :edit do - create_form - end - end - - view :new_in_modal, perms: :create, unknown: true, cache: :never, - wrap: { modal: { footer: "", size: :edit_modal_size, - title: :new_in_modal_title, - menu: :new_modal_menu } } do - _render_new_content_form - end - - def create_form - form_opts = new_in_modal_form_opts.reverse_merge(success: new_in_modal_success) - buttons = form_opts.delete(:buttons) || _render_new_buttons - - voo.title ||= new_view_title if new_name_prompt? - voo.show :help - card_form(:create, form_opts) do - create_form_with_alert_guide buttons - end - end - - def new_modal_size - :large - end - - def new_modal_menu - wrap_with_modal_menu do - [close_modal_window, render_bridge_link] - end - end - - def new_view_frame_and_form form_opts={} - buttons = form_opts.delete(:buttons) || _render_new_buttons - form_opts = form_opts.reverse_merge(success: new_success) - - with_nest_mode :edit do - voo.title ||= new_view_title if new_name_prompt? - voo.show :help - frame_and_form :create, form_opts do - create_form_with_alert_guide buttons - end - end - end - - def create_form_with_alert_guide buttons - wrap_with :div, class: "d-flex justify-content-between" do - [(wrap_with(:div, class: "w-100") do - [ - new_view_hidden, - new_view_name, - new_view_type, - _render_content_formgroups, - buttons - ] - end), - (alert_guide if voo.show?(:guide))] - end - end - - def new_view_hidden; end - - def new_in_modal_form_opts - { "data-slot-selector": "modal-origin", "data-slot-error-selector": ".card-slot", - buttons: _render_new_in_modal_buttons } - end - - def new_form_opts - { "data-main-success": JSON(redirect: true) } - end - - def new_view_title - output( - "New", - (card.type_name unless card.type_id == Card.default_type_id) - ) - end - - def new_in_modal_title - new_name_prompt? ? new_view_title : render_title - end - - def new_success - { mark: (card.rule(:thanks) || "_self") } - end - - def new_in_modal_success; end - - # NAME HANDLING - - def new_view_name - if new_name_prompt? - new_name_formgroup - elsif !autoname? - hidden_field_tag "card[name]", card.name - end - end - - def new_name_formgroup - output _render_name_formgroup, - hidden_field_tag("name_prompt", true) - end - - def new_name_prompt? - voo.visible? :name_formgroup do - needs_name? || params[:name_prompt] - end - end - - def needs_name? - card.name.blank? && !autoname? - end - - # TYPE HANDLING - - def new_view_type - if new_type_prompt? - _render_new_type_formgroup - else - hidden_field_tag "card[type_id]", card.type_id - end - end - - def new_type_prompt? - voo.visible? :new_type_formgroup do - !new_type_preset? && new_type_prompt_context? && new_type_permitted? - end - end - - def new_type_preset? - params[:type] || voo.type - end - - def new_type_prompt_context? - main? || card.simple? || card.is_template? - end - - def new_type_permitted? - Card.new(type_id: card.type_id).ok? :create - end - - view :new_type_formgroup do - wrap_type_formgroup do - type_field class: "type-field live-type-field", - href: path(view: :new), - "data-remote" => true - end - end - - view :new_buttons do - button_formgroup do - [standard_create_button, standard_cancel_button(cancel_button_new_args)] - end - end - - view :new_in_modal_buttons do - button_formgroup do - wrap_with "div", class: "d-flex" do - [standard_save_and_close_button(text: "Submit"), modal_cancel_button] - end - end - end - - # path to redirect to after canceling a new form - def cancel_button_new_args - href = case - when main? then path_to_previous - when voo&.home_view then path(view: voo.home_view) - else path(view: :unknown) - end - { href: href } - end - - def standard_create_button - submit_button class: "submit-button create-submit-button" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/new.rb ~~ diff --git a/set/mod011-edit/all/overlay_guide.rb b/set/mod011-edit/all/overlay_guide.rb deleted file mode 100644 index 909fcd4..0000000 --- a/set/mod011-edit/all/overlay_guide.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (OverlayGuide) -# -module OverlayGuide; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/overlay_guide.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :overlay_guide, - cache: :never, unknown: true, template: :haml, - wrap: { slot: { class: "_overlay d0-card-overlay card nodblclick" } } do - # TODO: use a common template for this and the nest editor - # (the common thing is that they both are an overlay of the bridge sidebar) - # and maybe make it look more like the overlay on the left with the same close icon - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/overlay_guide.rb ~~ diff --git a/set/mod011-edit/all/template_nest.rb b/set/mod011-edit/all/template_nest.rb deleted file mode 100644 index 3d4162b..0000000 --- a/set/mod011-edit/all/template_nest.rb +++ /dev/null @@ -1,51 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (TemplateNest) -# -module TemplateNest; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/all/template_nest.rb"; end -module Format; module_parent.send :register_set_format, Card::Format, self; extend Card::Set::AbstractFormat - view :template_nest, cache: :never, unknown: true do - return "" unless voo.nest_name - - if voo.nest_name.to_name.field_only? - with_nest_mode :normal do - nest template_link_set_name, view: :template_link - end - else - "{{#{voo.nest_syntax}}}" - end - end - - def template_link_set_name - name = voo.nest_name.to_name - if name.absolute? - name.trait_name :self - else - template_link_set_name_for_relative_name name - end - end - - def template_link_set_name_for_relative_name name - name = name.stripped.gsub(/^\+/, "") - - if (type = on_type_set) - [type, name].to_name.trait_name :type_plus_right - else - name.to_name.trait_name :right - end - end - - def on_type_set - return unless - (tmpl_set_name = parent.card.name.trunk_name) && - (tmpl_set_class_name = tmpl_set_name.tag_name) && - (tmpl_set_class_card = Card[tmpl_set_class_name]) && - (tmpl_set_class_card.codename == :type) - - tmpl_set_name.left_name - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/all/template_nest.rb ~~ diff --git a/set/mod011-edit/right/input_type.rb b/set/mod011-edit/right/input_type.rb deleted file mode 100644 index c79ca07..0000000 --- a/set/mod011-edit/right/input_type.rb +++ /dev/null @@ -1,44 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Right -# Set: All "+InputType" cards -# -module InputType; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/right/input_type.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def quick_editor - @submit_on_change = true - super - end - - def quick_form_opts - super.merge "data-update-foreign-slot": - ".card-slot.quick_edit-view.RIGHT-Xcontent_option_view" - end - - def default_input_type - :radio - end - - def raw_help_text - "edit interface for list cards" - end - - # def option_label_text option_name - # super.downcase - # end - - def quick_edit - card.left.prototype_default_card.try(:show_input_type?) ? super : "" - end -end - -def option_names - left.prototype_default_card&.try(:input_type_content_options) || super -end - -def supports_content_option_view? - item_name.in? ["checkbox", "radio", "filtered list"] -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/right/input_type.rb ~~ diff --git a/set/mod011-edit/self/input_type.rb b/set/mod011-edit/self/input_type.rb deleted file mode 100644 index 8ea8b27..0000000 --- a/set/mod011-edit/self/input_type.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Self -# Set: The card "InputType" -# -module InputType; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/self/input_type.rb"; end -setting_opts group: :editing, - position: 3, - rule_type_editable: false, - short_help_text: "edit interface" - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def raw_help_text - "Configure [[https://ace.c9.io/|ace]], "\ - "Decko's default code editor, using these available "\ - "[[https://github.com/ajaxorg/ace/wiki/Configuring-Ace|options]]." - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/self/input_type.rb ~~ diff --git a/set/mod011-edit/type/list.rb b/set/mod011-edit/type/list.rb deleted file mode 100644 index aec948b..0000000 --- a/set/mod011-edit/type/list.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "List" cards -# -module List; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/type/list.rb"; end -def input_type_content_options - ["multiselect", "checkbox", "autocompleted list", "filtered list"] -end - -def show_content_options? - true -end - -def show_input_type? - true -end - -def field_settings - %i[default help input_type content_options content_option_view] -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/type/list.rb ~~ diff --git a/set/mod011-edit/type/plain_text.rb b/set/mod011-edit/type/plain_text.rb deleted file mode 100644 index 8374258..0000000 --- a/set/mod011-edit/type/plain_text.rb +++ /dev/null @@ -1,22 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "PlainText" cards -# -module PlainText; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/type/plain_text.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def input_type_content_options - ["text area", "text field", "ace editor"] - end -end - -def field_settings - %i[default help input_type] -end - -def show_input_type? - true -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/type/plain_text.rb ~~ diff --git a/set/mod011-edit/type/pointer.rb b/set/mod011-edit/type/pointer.rb deleted file mode 100644 index 9a51516..0000000 --- a/set/mod011-edit/type/pointer.rb +++ /dev/null @@ -1,20 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Type -# Set: All "Pointer" cards -# -module Pointer; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/edit/set/type/pointer.rb"; end -def show_content_options? - true -end - -def show_input_type? - true -end - -def input_type_content_options - %w[select radio autocomplete] -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/edit/set/type/pointer.rb ~~ diff --git a/set/mod012-history/all/history.rb b/set/mod012-history/all/history.rb deleted file mode 100644 index 71bc9d5..0000000 --- a/set/mod012-history/all/history.rb +++ /dev/null @@ -1,119 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (History) -# -module History; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history.rb"; end -event :update_ancestor_timestamps, :integrate do - ids = history_ancestor_ids - return unless ids.present? - - Card.where(id: ids).update_all(updater_id: Auth.current_id, updated_at: Time.now) - ids.map { |anc_id| Card.expire anc_id.cardname } -end - -# track history (acts, actions, changes) on this card -def history? - true -end - -# all cards whose acts are considered part of this card's history -def history_card_ids - nestee_ids << id -end - -# all cards who are considered updated if this card's was updated -def history_parent_ids - nester_ids -end - -def history_ancestor_ids recursion_level=0 - return [] if recursion_level > 5 - - ids = history_parent_ids + - history_parent_ids.map { |id| Card[id].history_ancestor_ids(recursion_level + 1) } - ids.flatten -end - -# ~~FIXME~~: optimize (no need to instantiate all actions and changes!) -# Nothing is instantiated here. ActiveRecord is much smarter than you think. -# Methods like #empty? and #size make sql queries if their receivers are not already -# loaded -pk -def first_change? - # = update or delete - @current_action.action_type != :create && action_count == 2 && - create_action.card_changes.empty? -end - -def first_create? - @current_action.action_type == :create && action_count == 1 -end - -def action_count - Card::Action.where(card_id: @current_action.card_id).count -end - -# card has account that is responsible for prior acts -def has_edits? - Card::Act.where(actor_id: id).where("card_id IS NOT NULL").present? -end - -def changed_fields - Card::Change::TRACKED_FIELDS & (changed_attribute_names_to_save | saved_changes.keys) -end - -def nestee_ids - requiring_id { @nestee_ids ||= nesting_ids(:referee_id, :referer_id) } -end - -def nester_ids - requiring_id { @nester_ids ||= nesting_ids(:referer_id, :referee_id) } -end - -def diff_args - { diff_format: :text } -end - -# Delete all changes and old actions and make the last action the create action -# (that way the changes for that action will be created with the first update) -def make_last_action_the_initial_action - delete_all_changes - old_actions.delete_all - last_action.update! action_type: :create -end - -def clear_history - delete_all_changes - delete_old_actions -end - -def delete_old_actions - old_actions.delete_all -end - -def delete_all_changes - Card::Change.where(card_action_id: all_action_ids).delete_all -end - -def save_content_draft content - super - acts.create do |act| - act.ar_actions.build(draft: true, card_id: id, action_type: :update) - .card_changes.build(field: :db_content, value: content) - end -end - -private - -def nesting_ids return_field, where_field - Card::Reference.select(return_field).distinct.where( - ref_type: "I", where_field => id - ).pluck(return_field).compact -end - -def requiring_id - id ? yield : (return []) -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history.rb ~~ diff --git a/set/mod012-history/all/history/act_listing.rb b/set/mod012-history/all/history/act_listing.rb deleted file mode 100644 index 06536ac..0000000 --- a/set/mod012-history/all/history/act_listing.rb +++ /dev/null @@ -1,136 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, ActListing) -# -module ActListing; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/act_listing.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def act_from_context - if (act_id = params["act_id"]) - Act.find(act_id) || raise(Card::NotFound, "act not found") - else - card.last_action.act - end - end - - # used (by history and recent)for rendering act lists with legend and paging - # - # @param acts [ActiveRecord::Relation] relation that will return acts objects - # @param context [Symbol] :relative or :absolute - # @param draft_legend [Symbol] :show or :hide - def acts_layout acts, context, draft_legend=:hide - bs_layout container: false, fluid: false do - html _render_act_legend(draft_legend => :draft_legend) - row(12) { act_list acts, context } - row(12) { act_paging acts, context } - end - end - - def act_list acts, context - act_accordion acts, context do |act, seq| - fmt = context == :relative ? self : act.card.format(:html) - fmt.act_listing act, seq, context - end - end - - def act_listing act, seq=nil, context=nil - opts = act_listing_opts_from_params(seq) - opts[:slot_class] = "revision-#{act.id} history-slot list-group-item" - context ||= (params[:act_context] || :absolute).to_sym - act_renderer(context).new(self, act, opts).render - end - - # TODO: consider putting all these under one top-level param, eg: - # act: { seq: X, diff: [show/hide], action_view: Y } - def act_listing_opts_from_params seq - { act_seq: (seq || params["act_seq"]), - action_view: (params["action_view"] || "summary").to_sym, - hide_diff: params["hide_diff"].to_s.strip == "true" } - end - - def act_accordion acts, context, &block - accordion_group acts_for_accordion(acts, context, &block), nil, class: "clear-both" - end - - def acts_for_accordion acts, context - clean_acts(current_page_acts(acts)).map do |act| - with_act_seq(context, acts) do |seq| - yield act, seq - end - end - end - - def with_act_seq context, acts - yield(context == :absolute ? nil : current_act_seq(acts)) - end - - def current_act_seq acts - @act_seq = @act_seq ? (@act_seq -= 1) : act_list_starting_seq(acts) - end - - def clean_acts acts - # FIXME: if we get rid of bad act data, this will not be necessary - # The current - acts.select(&:card) - end - - def current_page_acts acts - acts.page(acts_page_from_params).per acts_per_page - end - - def act_list_starting_seq acts - acts.size - (acts_page_from_params - 1) * acts_per_page - end - - def acts_per_page - @acts_per_page ||= Card.config.acts_per_page || 10 - end - - def acts_page_from_params - @acts_page_from_params ||= params["page"].present? ? params["page"].to_i : 1 - end - - def act_paging acts, context - return unless controller.request # paginate requires a request - - wrap_with :div, class: "slotter btn-sm" do - paginate current_page_acts(acts), act_paging_opts(context) - end - end - - def act_paging_opts context - { remote: true, theme: "twitter-bootstrap-4" }.tap do |opts| - opts[:total_pages] = 10 if limited_paging? context - end - end - - def limited_paging? context - context == :absolute && Act.count > 1000 - end - - def action_icon action_type, extra_class=nil - icon = case action_type - when :create then :add_circle - when :update then :pencil - when :delete then :remove_circle - when :draft then :wrench - end - icon_tag icon, extra_class - end - - private - - def act_renderer context - case context - when :absolute - Act::ActRenderer::AbsoluteActRenderer - when :bridge - Act::ActRenderer::BridgeActRenderer - else # relative - Act::ActRenderer::RelativeActRenderer - end - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/act_listing.rb ~~ diff --git a/set/mod012-history/all/history/actions.rb b/set/mod012-history/all/history/actions.rb deleted file mode 100644 index cb53cb9..0000000 --- a/set/mod012-history/all/history/actions.rb +++ /dev/null @@ -1,137 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, Actions) -# -# -*- encoding : utf-8 -*- -module Actions; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/actions.rb"; end - -def all_action_ids - Card::Action.where(card_id: id).pluck :id -end - -def action_from_id action_id - return unless action_id.is_a?(Integer) || action_id =~ /^\d+$/ - - # if not an integer, action_id is probably a mod (e.g. if you request - # files/:logo/standard.png) - - action_if_on_self Action.fetch(action_id) -end - -def action_if_on_self action - return unless action.is_a? Action - - action if action.card_id == id -end - -def old_actions - actions.where("id != ?", last_action_id) -end - -def create_action - @create_action ||= actions.first -end - -def nth_action index - index = index.to_i - return unless id && index.positive? - - Action.where("draft is not true AND card_id = #{id}") - .order(:id).limit(1).offset(index - 1).first -end - -def new_content_action_id - return unless @current_action && current_action_changes_content? - - @current_action.id -end - -def current_action_changes_content? - new_card? || @current_action.new_content? || db_content_is_changing? -end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - def action_from_context - if (action_id = voo.action_id || params[:action_id]) - Action.fetch action_id - else - card.last_action - end - end - - def action_content action, view_type - return "" unless action.present? - - wrap do - [action_content_toggle(action, view_type), - content_diff(action, view_type)] - end - end - - def content_diff action, view_type - diff = action.new_content? && content_changes(action, view_type) - return "empty" unless diff.present? - - diff - end - - def action_content_toggle action, view_type - return unless show_action_content_toggle?(action, view_type) - - toggle_action_content_link action, view_type - end - - def show_action_content_toggle? action, view_type - view_type == :expanded || action.summary_diff_omits_content? - end - - def toggle_action_content_link action, view_type - other_view_type = view_type == :expanded ? :summary : :expanded - css_class = "revision-#{action.card_act_id} float-right" - link_to_view "action_#{other_view_type}", - icon_tag(action_arrow_dir(view_type), class: "md-24"), - class: css_class, - path: { action_id: action.id, look_in_trash: true } - end - - def action_arrow_dir view_type - view_type == :expanded ? :triangle_left : :triangle_right - end - - def revert_actions_link link_text, path_args, html_args={} - return unless card.ok? :update - - path_args.reverse_merge! action: :update, look_in_trash: true, assign: true, - card: { skip: :validate_renaming } - html_args.reverse_merge! remote: true, method: :post, rel: "nofollow", path: path_args - add_class html_args, "slotter" - link_to link_text, html_args - end - - def action_legend - types = %i[create update delete] - legend = types.map do |action_type| - "#{action_icon(action_type)} #{action_type}d" - end - legend << _render_draft_legend if voo.show?(:draft_legend) - "Actions: #{legend.join ' | '}" - end - - def content_legend - legend = [Card::Content::Diff.render_added_chunk("Additions"), - Card::Content::Diff.render_deleted_chunk("Subtractions")] - "Content changes: #{legend.join ' | '}" - end - - def content_changes action, diff_type, hide_diff=false - if hide_diff - action.raw_view - else - action.content_diff diff_type - end - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/actions.rb ~~ diff --git a/set/mod012-history/all/history/acts.rb b/set/mod012-history/all/history/acts.rb deleted file mode 100644 index c2d7131..0000000 --- a/set/mod012-history/all/history/acts.rb +++ /dev/null @@ -1,17 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, Acts) -# -# all acts with actions on self and on cards included in self (ie, acts shown in history) -module Acts; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/acts.rb"; end -def history_acts - @history_acts ||= Act.all_with_actions_on(history_card_ids, true).order id: :desc -end - -def draft_acts - drafts.created_by(Card::Auth.current_id).map(&:act) -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/acts.rb ~~ diff --git a/set/mod012-history/all/history/events.rb b/set/mod012-history/all/history/events.rb deleted file mode 100644 index c63e153..0000000 --- a/set/mod012-history/all/history/events.rb +++ /dev/null @@ -1,109 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, Events) -# -# must be called on all actions and before :set_name, :process_subcards and -module Events; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/events.rb"; end -# :validate_delete_children -event :assign_action, :initialize, when: :actionable? do - act = director.need_act - @current_action = Card::Action.create( - card_act_id: act.id, - action_type: action, - draft: (Env.params["draft"] == "true") - ) - if @supercard && @supercard != self - @current_action.super_action = @supercard.current_action - end -end - -# can we store an action? (can be overridden, eg in files) -def actionable? - history? -end - -event :detect_conflict, :validate, on: :update, when: :edit_conflict? do - errors.add :conflict, Cardio.t(:history_error_not_latest_revision) -end - -def edit_conflict? - last_action_id_before_edit && - last_action_id_before_edit.to_i != last_action_id && - (la = last_action) && - la.act.actor_id != Auth.current_id -end - -# stores changes in the changes table and assigns them to the current action -# removes the action if there are no changes -event :finalize_action, :finalize, when: :finalize_action? do - if changed_fields.present? - @current_action.update! card_id: id - - # NOTE: #last_change_on uses the id to sort by date - # so the changes for the create changes have to be created before the first change - store_card_changes_for_create_action if first_change? - store_card_changes unless first_create? - # FIXME: a `@current_action.card` call here breaks specs in solid_cache_spec.rb - elsif @current_action.card_changes.reload.empty? - @current_action.delete - @current_action = nil - end -end - -# changes for the create action are stored after the first update -def store_card_changes_for_create_action - Card::Action.cache.delete "#{create_action.id}-changes" - store_each_history_field create_action.id do |field| - attribute_before_act field - end -end - -def store_card_changes - store_each_history_field @current_action.id, changed_fields do |field| - self[field] - end -end - -def store_each_history_field action_id, fields=nil - fields ||= Card::Change::TRACKED_FIELDS - if false # Card::Change.supports_import? - # attach.feature fails with this - values = fields.map.with_index { |field, index| [index, yield(field), action_id] } - Card::Change.import %i[field value card_action_id], values # , validate: false - else - fields.each do |field| - Card::Change.create field: field, - value: yield(field), - card_action_id: action_id - end - end -end - -def finalize_action? - actionable? && current_action -end - -event :rollback_actions, :prepare_to_validate, on: :update, when: :rollback_request? do - update_args = process_revert_actions - Env.params["revert_actions"] = nil - update! update_args - clear_drafts - abort :success -end - -event :finalize_act, after: :finalize_action, when: :act_card? do - Card::Director.act.update! card_id: id -end - -event :remove_empty_act, :integrate_with_delay_final, when: :remove_empty_act? do - # Card::Director.act.delete - # Card::Director.act = nil -end - -def remove_empty_act? - act_card? && Director.act&.ar_actions&.reload&.empty? -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/events.rb ~~ diff --git a/set/mod012-history/all/history/last.rb b/set/mod012-history/all/history/last.rb deleted file mode 100644 index 62639ce..0000000 --- a/set/mod012-history/all/history/last.rb +++ /dev/null @@ -1,107 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, Last) -# -module Last; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/last.rb"; end -def acted_at - last_act.acted_at -end - -def revised_at - (last_action && (act = last_action.act) && act.acted_at) || Time.zone.now -end - -def last_change_on field, opts={} - action_id = extract_action_id(opts[:before] || opts[:not_after]) - - # If there is only one action then there are no entries in the changes table, - # so we can't do a sql search but the changes are accessible via the action. - if no_last_change? action_id, opts[:before] - nil - elsif create_action_last_change? action_id - create_action&.change field - else - last_change_from_action_id action_id, field, opts - end -end - -def no_last_change? action_id, before - before && action_id == create_action.id -end - -def create_action_last_change? action_id - action_id == create_action&.id || (!action_id && create_action&.sole?) -end - -def last_change_from_action_id action_id, field, opts - Change.joins(:action).where( - last_change_sql_conditions(opts), - card_id: id, - action_id: action_id, - field: Card::Change.field_index(field) - ).order(:id).last -end - -def last_change_sql_conditions opts - cond = "card_actions.card_id = :card_id AND field = :field" - cond += " AND (draft is not true)" unless opts[:including_drafts] - operator = "<" if opts[:before] - operator = "<=" if opts[:not_after] - cond += " AND card_action_id #{operator} :action_id" if operator - cond -end - -def last_action_id - last_action&.id -end - -def last_action - actions.where("id IS NOT NULL").last -end - -def last_content_action - last_change_on(:db_content)&.action -end - -def last_content_action_id - last_change_on(:db_content)&.card_action_id -end - -def last_actor - last_act.actor -end - -def last_act - @last_act ||= - if (action = last_action) - last_act_on_self = acts.last - act_of_last_action = action.act - return act_of_last_action unless last_act_on_self - return last_act_on_self unless act_of_last_action - - return last_act_on_self if act_of_last_action == last_act_on_self - - if last_act_on_self.acted_at > act_of_last_action.acted_at - last_act_on_self - else - act_of_last_action - end - end -end - -def previous_action action_id - return unless action_id - - action_index = actions.find_index { |a| a.id == action_id } - all_actions[action_index - 1] if action_index.to_i.nonzero? -end - -private - -def extract_action_id action_arg - action_arg.is_a?(Card::Action) ? action_arg.id : action_arg -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/last.rb ~~ diff --git a/set/mod012-history/all/history/revision.rb b/set/mod012-history/all/history/revision.rb deleted file mode 100644 index 4fccdca..0000000 --- a/set/mod012-history/all/history/revision.rb +++ /dev/null @@ -1,74 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, Revision) -# -module Revision; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/revision.rb"; end -def revision action, before_action=false - # a "revision" refers to the state of all tracked fields - # at the time of a given action - action = Card::Action.fetch(action) if action.is_a? Integer - return unless action - - if before_action - revision_before_action action - else - revision_attributes action - end -end - -def revision_attributes action - Card::Change::TRACKED_FIELDS.each_with_object({}) do |field, attr_changes| - last_change = action.change(field) || last_change_on(field, not_after: action) - attr_changes[field.to_sym] = (last_change ? last_change.value : self[field]) - end -end - -def revision_before_action action - if (prev_action = action.previous_action) - revision prev_action - else - { trash: true } - end -end - -def rollback_request? - history? && actions_to_revert.any? -end - -def process_revert_actions revert_actions=nil - revert_actions ||= actions_to_revert - update_args = { subcards: {} } - reverting_to_previous = Env.params["revert_to"] == "previous" - revert_actions.each do |action| - merge_revert_action! action, update_args, reverting_to_previous - end - update_args -end - -def actions_to_revert - if (act_id = Env.params["revert_act"]) - Act.find(act_id).actions - else - explicit_actions_to_revert - end -end - -def explicit_actions_to_revert - Array.wrap(Env.params["revert_actions"]).map do |a_id| - Action.fetch(a_id) || nil - end.compact -end - -def merge_revert_action! action, update_args, reverting_to_previous - rev = action.card.revision(action, reverting_to_previous) - rev.delete :name unless rev[:name] # handles null name field in compound cards - if action.card_id == id - update_args.merge! rev - else - update_args[:subcards][action.card.name] = rev - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/revision.rb ~~ diff --git a/set/mod012-history/all/history/selected.rb b/set/mod012-history/all/history/selected.rb deleted file mode 100644 index cbaecec..0000000 --- a/set/mod012-history/all/history/selected.rb +++ /dev/null @@ -1,73 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, Selected) -# -# if these aren't in a nested module, the methods just overwrite the base -# methods, but we need a distinct module so that super will be able to refer to -module Selected; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/selected.rb"; end -# the base methods. -def content - @selected_action_id ? selected_content : super -end - -def content= value - @selected_content = nil - super -end - -def select_action_by_params params - action = nth_action(params[:rev]) || action_from_id(params[:rev_id]) - return unless action - - select_action action.id -end - -def select_action action_id - run_callbacks :select_action do - self.selected_action_id = action_id - end -end - -def selected_action_id - @selected_action_id || @current_action&.id || last_action_id -end - -def selected_action_id= action_id - @selected_content = nil - @selected_action_id = action_id -end - -def selected_action - selected_action_id && Action.fetch(selected_action_id) -end - -def selected_content - @selected_content ||= content_at_time_of_selected_action || db_content -end - -def content_at_time_of_selected_action - last_change_on(:db_content, not_after: selected_action_id, - including_drafts: true)&.value -end - -def with_selected_action_id action_id - current_action_id = @selected_action_id - select_action_id action_id - result = yield - select_action_id current_action_id - result -end - -def select_action_id action_id - run_callbacks :select_action do - self.selected_action_id = action_id - end -end - -def selected_content_action_id - @selected_action_id || new_content_action_id || last_content_action_id -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/selected.rb ~~ diff --git a/set/mod012-history/all/history/views.rb b/set/mod012-history/all/history/views.rb deleted file mode 100644 index a673d2c..0000000 --- a/set/mod012-history/all/history/views.rb +++ /dev/null @@ -1,75 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All; module History; -# Set: All cards (History, Views) -# -# History views -module Views; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history/views.rb"; end - -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :history, cache: :never do - frame do - class_up "d0-card-body", "history-slot" - acts_layout card.history_acts, :relative, :show - end - end - - view :act, cache: :never do - act_listing act_from_context - end - - view :act_legend do - bs_layout do - row md: [12, 12], lg: [7, 5] do - col action_legend - col content_legend, class: "text-right" - end - end - end - - view :draft_legend do - "#{action_icon(:draft)} unsaved draft" - end - - view :action_summary do - action_content action_from_context, :summary - end - - view :action_expanded do - action_content action_from_context, :expanded - end - - view :change do - voo.show :title_link - voo.hide :menu - wrap do - [_render_title, - _render_menu, - _render_last_action] - end - end - - view :last_action do - %( - - #{render_last_action_verb} #{render_acted_at} ago by - #{nest card.last_actor, view: :link} - - ) - end - - view :last_action_verb, cache: :never do - return unless (act = card.last_act) - return unless (action = act.action_on card.id) - - case action.action_type - when :create then "added" - when :delete then "deleted" - else - link_to_view :history, "edited", class: "last-edited", rel: "nofollow" - end - end -end -end;end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history/views.rb ~~ diff --git a/set/mod012-history/all/history_bridge.rb b/set/mod012-history/all/history_bridge.rb deleted file mode 100644 index 8334054..0000000 --- a/set/mod012-history/all/history_bridge.rb +++ /dev/null @@ -1,88 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class All -# Set: All cards (HistoryBridge) -# -module HistoryBridge; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/history/set/all/history_bridge.rb"; end -module HtmlFormat; module_parent.send :register_set_format, Card::Format::HtmlFormat, self; extend Card::Set::AbstractFormat - view :creator_credit, - wrap: { div: { class: "text-muted creator-credit" } }, cache: :never do - return "" unless card.real? - - "Created by #{nest card.creator, view: :link} "\ - "#{time_ago_in_words(card.created_at)} ago" - end - - view :updated_by, wrap: { div: { class: "text-muted" } } do - updaters = Card.search(updater_of: { id: card.id }) if card.id - return "" unless updaters.present? - - links = updater_links updaters, others_target: card.fetch(:editors) - "Updated by #{links}" - end - - def acts_bridge_layout acts, context=:bridge - output [ - _render_creator_credit, - act_link_list(acts, context), - act_paging(acts, context) - ] - end - - def act_link_list acts, context - items = acts_for_accordion(acts, context) do |act, seq| - act_link_list_item act, seq, context - end - bridge_pills items - end - - def act_link_list_item act, seq=nil, _context=nil - opts = act_listing_opts_from_params(seq) - opts[:slot_class] = "revision-#{act.id} history-slot nav-item" - act_renderer(:bridge).new(self, act, opts).bridge_link - end - - def act_list_group acts, context, &block - list_group acts_for_accordion(acts, context, &block), class: "clear-both" - end - - view :bridge_act, cache: :never do - opts = act_listing_opts_from_params(nil) - act = act_from_context - ar = act_renderer(:bridge).new(self, act, opts) - class_up "action-list", "my-3" - wrap_with_overlay title: ar.overlay_title, slot: breadcrumb_data("History") do - act_listing(act, opts[:act_seq], :bridge) - end - end - - private - - def updater_links updaters, item_view: :link, max_count: 3, others_target: card - total = updaters.size - num_to_show = number_of_updaters_to_show total, max_count - - links = - links_to_updaters(updaters, num_to_show, item_view) + - link_to_other_updaters(total, others_target, num_to_show) - - links.to_sentence - end - - def number_of_updaters_to_show total, max_count - total > max_count ? max_count - 1 : max_count - end - - def links_to_updaters updaters, num_to_show, item_view - updaters[0..(num_to_show - 1)].map { |c| nest c, view: item_view } - end - - def link_to_other_updaters total, target, num_to_show - return [] unless total > num_to_show - - link_to_card target, "#{total - num_to_show} others" - end -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/history/set/all/history_bridge.rb ~~ diff --git a/set/mod013-carrierwave/abstract/attachment.rb b/set/mod013-carrierwave/abstract/attachment.rb deleted file mode 100644 index 82e0b56..0000000 --- a/set/mod013-carrierwave/abstract/attachment.rb +++ /dev/null @@ -1,144 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract -# Set: Abstract (Attachment) -# -module Attachment; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/carrierwave/set/abstract/attachment.rb"; end -attr_writer :empty_ok - -def self.included host_class - host_class.extend CarrierWave::CardMount -end - -event :select_file_revision, after: :select_action do - attachment.retrieve_from_store!(attachment.identifier) -end - -# we need a card id for the path so we have to update db_content when we have -# an id -event :correct_identifier, :finalize, on: :create, when: proc { |c| !c.web? } do - update_column(:db_content, attachment.db_content) - expire -end - -event :save_original_filename, :prepare_to_store, on: :save, when: :file_ready_to_save? do - return unless @current_action - - @current_action.update! comment: original_filename -end - -event :validate_file_exist, :validate, on: :create do - return if empty_ok? - - if will_be_stored_as == :web - errors.add "url is missing" if content.blank? - elsif !attachment.file.present? - errors.add attachment_name, "is missing" - end -end - -event :write_identifier, after: :save_original_filename, when: proc { |c| !c.web? } do - self.content = attachment.db_content -end - -def file_ready_to_save? - attachment.file.present? && - !preliminary_upload? && - !save_preliminary_upload? && - attachment_is_changing? -end - -# needed for flexmail attachments. hacky. -def item_names _args={} - [name] -end - -def original_filename - return content.split("/").last if web? - - attachment.original_filename -end - -def unfilled? - !attachment.present? && !save_preliminary_upload? && !subcards? && blank_content? -end - -def attachment_changed? - send "#{attachment_name}_changed?" -end - -def attachment_is_changing? - send "#{attachment_name}_is_changing?" -end - -def attachment_before_act - send "#{attachment_name}_before_act" -end - -def create_versions? _new_file - true -end - -def empty_ok? - @empty_ok -end - -def assign_set_specific_attributes - # reset content if we really have something to upload - self.content = nil if set_specific[attachment_name].present? - super -end - -def delete_files_for_action action - with_selected_action_id(action.id) do - attachment.file.delete - attachment.versions.each_value do |version| - version.file.delete - end - end -end - -def revision action, before_action=false - return unless (result = super) - - result[:empty_ok] = true - result -end - -def attachment_format ext - rescuing_extension_issues do - return unless ext.present? && original_extension - - confirm_original_extension(ext) || detect_extension(ext) - end -end - -def rescuing_extension_issues - yield -rescue StandardError => e - Rails.logger.info "attachment_format issue: #{e.message}" - nil -end - -def detect_extension ext - return unless (mime_types = MIME::Types[attachment.content_type]) - - recognized_extension?(mime_types, ext) ? ext : mime_types[0].extensions[0] -end - -def recognized_extension? mime_types, ext - mime_types.find { |mt| mt.extensions.member? ext } -end - -def confirm_original_extension ext - return unless ["file", original_extension].member? ext - - original_extension -end - -def original_extension - @original_extension ||= attachment&.extension&.sub(/^\./, "") -end -end;end;end;end; -# ~~ generated from /Users/ezl5238/dev/decko/gem/mod/carrierwave/set/abstract/attachment.rb ~~ diff --git a/set/mod013-carrierwave/abstract/attachment/cloud.rb b/set/mod013-carrierwave/abstract/attachment/cloud.rb deleted file mode 100644 index b5eaf50..0000000 --- a/set/mod013-carrierwave/abstract/attachment/cloud.rb +++ /dev/null @@ -1,146 +0,0 @@ -# -*- encoding : utf-8 -*- -class Card; module Set; class Abstract; module Attachment; -# Set: Abstract (Attachment, Cloud) -# -module Cloud; -extend Card::Set -def self.source_location; "/Users/ezl5238/dev/decko/gem/mod/carrierwave/set/abstract/attachment/cloud.rb"; end -event :change_bucket_if_read_only, :initialize, - on: :update, when: :change_bucket_if_read_only? do - @new_storage_type = storage_type_from_config -end - -event :validate_storage_type_update, :validate, on: :update, when: :cloud? do - # FIXME: make it possible to retrieve the file from cloud storage - # to store it somewhere else. Currently, it only works to change the - # storage type if a new file is provided - # i.e. `update storage_type: :local` fails but - # `update storage_type: :local, file: [file handle]` is ok - return unless storage_type_changed? && !attachment_is_changing? - - errors.add :storage_type, t(:carrierwave_moving_files_is_not_supported) -end - -def bucket - @bucket ||= cloud? && (new_card_bucket || bucket_from_content || bucket_from_config) -end - -def new_card_bucket - return unless new_card? - - # If the file is assigned before the bucket option we have to - # check if there is a bucket options in set_specific. - # That happens for exmaple when the file appears before the bucket in the - # options hash: - # Card.create file: file_handle, bucket: "my_bucket" - set_specific[:bucket] || set_specific["bucket"] || bucket_from_config -end - -def bucket_config - @bucket_config ||= load_bucket_config -end - -def load_bucket_config - return {} unless bucket - - bucket_config = Cardio.config.file_buckets&.dig(bucket.to_sym) || {} - bucket_config.symbolize_keys! - bucket_config[:credentials]&.symbolize_keys! - # we don't want :attributes hash symbolized, so we can't use - # deep_symbolize_keys - ensure_bucket_config do - load_bucket_config_from_env bucket_config - end -end - -def ensure_bucket_config - yield.tap do |config| - require_configuration! config - require_credentials! config - end -end - -def require_configuration! config - cant_find_in_bucket! "configuration" unless config.present? -end - -def require_credentials! config - cant_find_in_bucket! "credentials" unless config[:credentials] -end - -def cant_find_in_bucket! need - raise Card::Error, "couldn't find #{need} for bucket #{bucket}" -end - -def load_bucket_config_from_env config - config ||= {} - each_config_option_from_env do |key| - replace_with_env_variable config, key - end - credential_config config do |cred_hash| - load_bucket_credentials_from_env cred_hash - end -end - -def credential_config config - config[:credentials] ||= {} - yield config[:credentials] - config.delete :credentials if config[:credentials].blank? - config -end - -def each_config_option_from_env - CarrierWave::FileCardUploader::CONFIG_OPTIONS.each do |key| - yield key unless key.in? %i[attributes credentials] - end -end - -def load_bucket_credentials_from_env cred_config - each_credential_from_env do |option| - replace_with_env_variable cred_config, option, "credentials" - end -end - -def each_credential_from_env - regexp = credential_from_env_regexp - ENV.each_key do |env_key| - next unless (m = regexp.match env_key) - - yield m[:option].downcase.to_sym - end -end - -def credential_from_env_regexp - Regexp.new "^(?:#{bucket.to_s.upcase}_)?CREDENTIALS_(?