Sha256: 337d4815070cfa034a7d2edeecf23bb3ca77933a6190bf7e6c7f7aeae9d94f3d

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 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) and rule.type_id==Card::PointerID and 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(/&/, "&amp;").gsub(/\'/, "&apos;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
    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

2 entries across 2 versions & 1 rubygems

Version Path
card-1.16.6 mod/01_core/format/html_format.rb
card-1.16.5 mod/01_core/format/html_format.rb