Sha256: bdfb0d2929c8faccc23c9e72021b3733e4c84c32c547acd3c580c80ab02419c7
Contents?: true
Size: 1.97 KB
Versions: 14
Compression:
Stored size: 1.97 KB
Contents
# -*- encoding : utf-8 -*- require_dependency 'card/diff' class Card Format.register :html class HtmlFormat < Format include Diff attr_accessor :options_need_save, :start_time, :skip_autosave # builtin layouts allow for rescue / testing LAYOUTS = Loader.load_layouts.merge 'none' => '{{_main}}' # helper methods for layout view def get_layout_content Auth.as_bot do if requested_layout = params[:layout] layout_from_card_or_code requested_layout else layout_from_rule end end end def layout_from_rule if (rule = card.rule_card(:layout)) && rule.type_id == Card::PointerID && (layout_name = rule.item_names.first) layout_from_card_or_code layout_name end end def layout_from_card_or_code name layout_card = Card.fetch name.to_s, skip_virtual: true, skip_modules: true if layout_card and layout_card.ok? :read layout_card.content elsif (hardcoded_layout = LAYOUTS[name]) hardcoded_layout else "<h1>Unknown layout: #{name}</h1>Built-in Layouts: #{LAYOUTS.keys.join(', ')}" end end def get_inclusion_defaults nested_card {view: (nested_card.rule( :default_html_view ) || :titled) } end def default_item_view :closed end def output content case content when String; content when Array ; content.compact.join "\n" end end def html_escape_except_quotes s # to be used inside single quotes (makes for readable json attributes) s.to_s.gsub(/&/, "&").gsub(/\'/, "'").gsub(/>/, ">").gsub(/</, "<") end def main? if show_layout? @depth == 1 && @mainline #assumes layout includes {{_main}} else @depth == 0 && params[:is_main] end end def focal? # meaning the current card is the requested card if show_layout? main? else @depth == 0 end end end end
Version data entries
14 entries across 14 versions & 1 rubygems