Class: Idml::Render::ConditionFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/idml/render/condition_filter.rb

Overview

Resolves whether a styled run should render based on its AppliedConditions and the visibility flags declared on the corresponding <Condition> elements in designmap.xml.

A run is visible when either:

  • It has no AppliedConditions (the common case), OR
  • Every condition it references is itself Visible.

A run is hidden when ANY referenced condition is hidden. This matches InDesign's "hide any text the user has toggled off" semantics.

Construction: ConditionFilter.from_designmap(designmap) reads the condition collection and indexes by Self. Use filter.visible?(applied_conditions_string) per run; pass nil or empty string for untagged runs.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conditions) ⇒ ConditionFilter

Returns a new instance of ConditionFilter.



27
28
29
30
31
# File 'lib/idml/render/condition_filter.rb', line 27

def initialize(conditions)
  @visibility_by_self = conditions.to_h do |cond|
    [cond.self_attr, condition_visible?(cond)]
  end
end

Class Method Details

.from_designmap(designmap) ⇒ Object



22
23
24
25
# File 'lib/idml/render/condition_filter.rb', line 22

def self.from_designmap(designmap)
  conditions = designmap ? designmap.condition : []
  new(conditions)
end

Instance Method Details

#visible?(applied_conditions) ⇒ Boolean

applied_conditions is the raw PSR/CSR string. IDML encodes it as a space-separated list of condition Self IDs. Returns true when the run should render.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/idml/render/condition_filter.rb', line 36

def visible?(applied_conditions)
  return true if applied_conditions.nil?
  return true if applied_conditions.strip.empty?

  applied_conditions.split.uniq.all? do |cond_self|
    condition_visible?(cond_self)
  end
end