Sha256: 1e4ec186ecdb02e853520d815426a7a3d0040ed5d7016d4259e6cc966563ae53

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

basket[:non_createable_types] << :setting

format :data do
  view :core do
    cql = { left: { type: SetID },
            right: card.id,
            limit: 0 }
    Card.search(cql).compact.map { |c| nest c }
  end
end

def count
  Card.search left: { type: SetID }, right: id, limit: 0, return: :count
end

def set_classes_with_rules
  Pattern.concrete.reverse.map do |set_class|
    rules = rules_for_set_class set_class
    [set_class, rules] unless rules.empty?
  end.compact
end

def rules_for_set_class set_class
  cql = { left: { type: SetID }, right: id, sort_by: %w[content name], limit: 0 }
  cql[:left][(set_class.anchorless? ? :id : :right_id)] = set_class.pattern_id
  Card.search cql
end

format :html do
  def rule_link rule, text
    link_to_card rule, text, path: { view: :modal_rule },
                             slotter: true, "data-modal-class": "modal-lg"
  end

  view :core do
    haml do
      <<-'HAML'.strip_heredoc
        = _render_rule_help
        %h3 All #{card.name.tr "*", ""} rules that apply to
        - card.set_classes_with_rules.each do |klass, rules|
          %p
            %h5
              = klass.generic_label.downcase
            - if klass.anchorless?
              = nest rules.first, view: :bar, show: :full_name
            - else
              - rules.each do |rule|
                = nest rule, view: :bar
      HAML
    end
  end

  # Because +*help content renders in "template" mode when you render its content
  # directly, we render the help text in the context of the *all+<setting> card
  view :rule_help do
    nest [:all, card.name], view: :rule_help
  end

  view :one_line_content do
    render_rule_help
  end
end

format :json do
  def items_for_export
    Card.search left: { type: SetID }, right: card.id, limit: 0
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
card-mod-rules-0.16.0 set/type/setting.rb
card-mod-rules-0.15.6 set/type/setting.rb
card-mod-rules-0.15.5 set/type/setting.rb
card-mod-rules-0.15.4 set/type/setting.rb
card-mod-rules-0.15.3 set/type/setting.rb
card-mod-rules-0.15.2.pre1 set/type/setting.rb
card-mod-rules-0.15.1.1 set/type/setting.rb
card-mod-rules-0.15.1 set/type/setting.rb
card-mod-rules-0.15.0 set/type/setting.rb