-
Notifications
You must be signed in to change notification settings - Fork 22
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 #213 from ONLYOFFICE/feature/add-parsing-preset-color
Add parsing `PresetColor` to `GradientStop`
- Loading branch information
Showing
6 changed files
with
50 additions
and
8 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
27 changes: 20 additions & 7 deletions
27
...parser/common_parser/common_data/colors/presentation_fill/gradient_color/gradient_stop.rb
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,15 +1,28 @@ | ||
require_relative 'gradient_stop/preset_color' | ||
module OoxmlParser | ||
class GradientStop < OOXMLDocumentObject | ||
attr_accessor :position, :color | ||
|
||
def initialize(position) | ||
@position = position | ||
end | ||
# Parse GradientStop object | ||
# @param node [Nokogiri::XML:Element] node to parse | ||
# @return [GradientStop] result of parsing | ||
def parse(node) | ||
node.attributes.each do |key, value| | ||
case key | ||
when 'pos' | ||
@position = value.value.to_i / 1_000 | ||
end | ||
end | ||
|
||
def self.parse(gs_node) | ||
gradient_stop = GradientStop.new(gs_node.attribute('pos').value.to_i / 1_000) | ||
gs_node.xpath('*').each { |color_node| gradient_stop.color = Color.parse_color(color_node) } | ||
gradient_stop | ||
node.xpath('*').each do |node_child| | ||
@color = case node_child.name | ||
when 'prstClr' | ||
PresetColor.new(parent: self).parse(node_child) | ||
else | ||
Color.parse_color(node_child) | ||
end | ||
end | ||
self | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
..._parser/common_data/colors/presentation_fill/gradient_color/gradient_stop/preset_color.rb
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,20 @@ | ||
module OoxmlParser | ||
# Class for working with `a:prstClr` tag | ||
class PresetColor < OOXMLDocumentObject | ||
# @return [String] value of preset color | ||
attr_accessor :value | ||
|
||
# Parse PresetColor object | ||
# @param node [Nokogiri::XML:Element] node to parse | ||
# @return [PresetColor] result of parsing | ||
def parse(node) | ||
node.attributes.each do |key, value| | ||
case key | ||
when 'val' | ||
@value = value.value.to_s | ||
end | ||
end | ||
self | ||
end | ||
end | ||
end |
Binary file added
BIN
+5.88 KB
...ies/fill_color/value/gradient_stops/gradient_stops_color/gradient_stops_color_preset.xlsx
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
...eet/drawing/shape/properties/fill_color/value/gradient_stops/gradient_stops_color_spec.rb
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,8 @@ | ||
require 'spec_helper' | ||
|
||
describe 'My behaviour' do | ||
it 'gradient_fill.xlsx' do | ||
xlsx = OoxmlParser::XlsxParser.parse_xlsx('spec/workbook/worksheet/drawing/shape/properties/fill_color/value/gradient_stops/gradient_stops_color/gradient_stops_color_preset.xlsx') | ||
expect(xlsx.worksheets[0].drawings.first.shape.properties.fill_color.value.gradient_stops.first.color.value).to eq('lightYellow') | ||
end | ||
end |