-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from rickychilcott/feature/full-style-support
Fully Support Styles
- Loading branch information
Showing
17 changed files
with
828 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'docx/containers/container' | ||
require 'docx/elements/style' | ||
|
||
module Docx | ||
module Elements | ||
module Containers | ||
StyleNotFound = Class.new(StandardError) | ||
|
||
class StylesConfiguration | ||
def initialize(raw_styles) | ||
@raw_styles = raw_styles | ||
@styles_parent_node = raw_styles.root | ||
end | ||
|
||
attr_reader :styles, :styles_parent_node | ||
|
||
def styles | ||
styles_parent_node | ||
.children | ||
.filter_map do |style| | ||
next unless style.get_attribute("w:styleId") | ||
|
||
Elements::Style.new(self, style) | ||
end | ||
end | ||
|
||
def style_of(id_or_name) | ||
styles.find { |style| style.id == id_or_name || style.name == id_or_name } || raise(Errors::StyleNotFound, "Style name or id '#{id_or_name}' not found") | ||
end | ||
|
||
def size | ||
styles.size | ||
end | ||
|
||
def add_style(id, attributes = {}) | ||
Elements::Style.create(self, {id: id, name: id}.merge(attributes)) | ||
end | ||
|
||
def remove_style(id) | ||
style = styles.find { |style| style.id == id } | ||
|
||
style.node.remove | ||
styles.delete(style) | ||
end | ||
|
||
def serialize(**options) | ||
@raw_styles.serialize(**options) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'docx/elements/bookmark' | ||
require 'docx/elements/element' | ||
require 'docx/elements/text' | ||
require 'docx/elements/text' | ||
require 'docx/elements/style' |
Oops, something went wrong.