Skip to content

Commit ec63983

Browse files
committed
Add level override
1 parent 1e2305c commit ec63983

6 files changed

Lines changed: 75 additions & 10 deletions

File tree

examples/numbering

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ package.styles << list_style
3535

3636
# Create an abstract number that describes a bulleted list:
3737
abstract_number = AbstractNumber.new(0)
38-
#abstract_number.multi_level_type = :hybridMultilevel
38+
3939
# Each number can have multiple levels. Define the first level as a bulleted list:
4040
level_0 = Level.new
4141
level_0.level = 0

lib/openxml/docx/elements/level.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ class Level < OpenXml::Docx::Element
66
tag :lvl
77

88
with_namespace :w do
9-
attribute :level, expects: :integer, displays_as: :ilvl
10-
# The following are "UI attributes:" tplc is an entirely opaque
11-
# Word "template code" and "tenative" just means it wasn't used but
12-
# was generated anyway.
9+
attribute :level, expects: :integer, displays_as: :ilvl # required
10+
# tplc is an entirely opaque "Word template code" and is
11+
# "application-specific" according to the spec
1312
# attribute :tplc
14-
# attribute :tentative
13+
attribute :tentative, expects: :boolean
1514
end
1615

1716
value_property :start
1817
value_property :number_format
19-
# value_property :lvl_restart
18+
value_property :level_restart
2019
# value_property :p_style
2120
# value_property :is_lgl
22-
# value_property :suff
21+
value_property :suffix
2322
value_property :level_text
2423
# value_property :lvl_pic_bullet_id
2524
value_property :alignment, as: :level_alignment
@@ -37,8 +36,14 @@ def property_xml(xml)
3736
return if props.none?(&:render?)
3837

3938
props.each { |prop| prop.to_xml(xml) }
40-
@paragraph_style.property_xml(xml) unless @paragraph_style.nil?
41-
@character_style.property_xml(xml) unless @character_style.nil?
39+
end
40+
41+
def to_xml(xml)
42+
xml["w"].public_send(tag, xml_attributes) {
43+
property_xml(xml)
44+
@paragraph_style.property_xml(xml) unless @paragraph_style.nil?
45+
@character_style.property_xml(xml) unless @character_style.nil?
46+
}
4247
end
4348
end
4449
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module OpenXml
2+
module Docx
3+
module Elements
4+
class LevelOverride < OpenXml::Docx::Element
5+
include HasChildren, HasProperties
6+
tag :lvlOverride
7+
8+
with_namespace :w do
9+
attribute :level, expects: :integer, displays_as: :ilvl # required
10+
end
11+
12+
value_property :start_override
13+
14+
def override
15+
@override ||= Level.new
16+
end
17+
18+
def to_xml(xml)
19+
xml["w"].public_send(tag, xml_attributes) {
20+
start_override.to_xml(xml)
21+
@override.to_xml(xml) unless @override.nil?
22+
}
23+
end
24+
end
25+
end
26+
end
27+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module OpenXml
2+
module Docx
3+
module Properties
4+
class LevelRestart < IntegerProperty
5+
tag :lvlRestart
6+
7+
end
8+
end
9+
end
10+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module OpenXml
2+
module Docx
3+
module Properties
4+
class StartOverride < IntegerProperty
5+
tag :startOverride
6+
7+
end
8+
end
9+
end
10+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module OpenXml
2+
module Docx
3+
module Properties
4+
class Suffix < ValueProperty
5+
tag :suff
6+
7+
def ok_values
8+
%i(tab space nothing)
9+
end
10+
end
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)