diff options
| author | Randy Morgan <[email protected]> | 2011-12-02 18:35:32 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-12-02 18:35:32 +0900 |
| commit | 3def8f8895a62783cf2e36152d786429e25bb90e (patch) | |
| tree | 61d9ee104db312c30a8c61a4f80db9343e4f2a2a /lib | |
| parent | 6439ce4d2ec5c97ad82a8dc10d974ca9754f2113 (diff) | |
| download | caxlsx-3def8f8895a62783cf2e36152d786429e25bb90e.tar.gz caxlsx-3def8f8895a62783cf2e36152d786429e25bb90e.zip | |
Added locking attributes for pictures and some stubs for parsing
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/drawing/drawing.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 7 | ||||
| -rw-r--r-- | lib/axlsx/package.rb | 21 | ||||
| -rw-r--r-- | lib/axlsx/util/parser.rb | 35 | ||||
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 11 |
6 files changed, 69 insertions, 11 deletions
diff --git a/lib/axlsx.rb b/lib/axlsx.rb index 7c15672c..71755f5b 100644 --- a/lib/axlsx.rb +++ b/lib/axlsx.rb @@ -5,6 +5,10 @@ Encoding::default_external = 'UTF-8' unless RUBY_VERSION < '1.9' require 'axlsx/util/simple_typed_list.rb' require 'axlsx/util/constants.rb' require 'axlsx/util/validators.rb' + +# to be included with parsable intitites. +#require 'axlsx/util/parser.rb' + require 'axlsx/stylesheet/styles.rb' require 'axlsx/doc_props/app.rb' diff --git a/lib/axlsx/drawing/drawing.rb b/lib/axlsx/drawing/drawing.rb index 4fa7dc11..6e41f6a5 100644 --- a/lib/axlsx/drawing/drawing.rb +++ b/lib/axlsx/drawing/drawing.rb @@ -27,7 +27,7 @@ module Axlsx require 'axlsx/drawing/bar_3D_chart.rb' require 'axlsx/drawing/line_3D_chart.rb' - + require 'axlsx/drawing/picture_locking.rb' require 'axlsx/drawing/pic.rb' # A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors. diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 84e750ce..4d970e32 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -26,6 +26,8 @@ module Axlsx # @return [OneCellAnchor] attr_reader :anchor + # The picture locking attributes for this picture + attr_reader :picture_locking # Creates a new Pic(ture) object # @param [Anchor] anchor the anchor that holds this image @@ -43,6 +45,7 @@ module Axlsx end start_at(*options[:start_at]) if options[:start_at] yield self if block_given? + @picture_locking = PictureLocking.new(options) end def image_src=(v) @@ -94,7 +97,7 @@ module Axlsx def width=(v) @anchor.width = v end - + # providing access to update the anchor's height attribute # @param [Integer] v # @see OneCellAnchor.width @@ -126,7 +129,7 @@ module Axlsx xml.send('xdr:nvPicPr') { xml.send('xdr:cNvPr', :id=>"2", :name=>name, :descr=>descr) xml.send('xdr:cNvPicPr') { - xml.send('a:picLocks', :noChangeAspect=>1) + picture_locking.to_xml(xml) } } xml.send('xdr:blipFill') { diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 5c46776c..d9b308ae 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -16,12 +16,6 @@ module Axlsx yield self if block_given? end - # Accepts a ruport table for serialization to xlsx - # @param [Table] table a ruport Table object - def ruport_table(table) - puts table - end - # The workbook this package will serialize or validate. # @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned. # @raise ArgumentError if workbook parameter is not a Workbook instance. @@ -39,6 +33,18 @@ module Axlsx yield @workbook if block_given? @workbook end + + #def self.parse(input, confirm_valid = false) + # p = Package.new + # z = Zip::ZipFile.open(input) + # p.workbook = Workbook.parse z.get_entry(WORKBOOK_PN) + # p + #end + + + + + # @see workbook def workbook=(workbook) DataTypeValidator.validate "Package.workbook", Workbook, workbook; @workbook = workbook; end @@ -76,7 +82,8 @@ module Axlsx end true end - + + # Validate all parts of the package against xsd schema. # @return [Array] An array of all validation errors found. # @note This gem includes all schema from OfficeOpenXML-XMLSchema-Transitional.zip and OpenPackagingConventions-XMLSchema.zip diff --git a/lib/axlsx/util/parser.rb b/lib/axlsx/util/parser.rb new file mode 100644 index 00000000..68523ebf --- /dev/null +++ b/lib/axlsx/util/parser.rb @@ -0,0 +1,35 @@ +module Axlsx + # The Parser module mixes in a number of methods to help in generating a model from xml + module Parser + attr_accessor :parser_xml + + def parse_string attr_name, xpath + send("#{attr_name.to_s}=", parse_value(xpath)) + end + + def parse_symbol attr_name, xpath + v = parse_value xpath + v = v.to_sym unless v.nil? + send("#{attr_name.to_s}=", v) + end + + def parse_integer attr_name, xpath + v = parse_value xpath + v = v.to_i if v.respond_to?(:to_i) + send("#{attr_name.to_s}=", v) + end + + def parse_float attr_name, xpath + v = parse_value xpath + v = v.to_f if v.respond_to?(:to_f) + send("#{attr_name.to_s}=", v) + end + + def parse_value xpath + node = parser_xml.xpath(xpath) + return nil if node.empty? + node.text.strip + end + + end +end diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 65020e71..e0031d15 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -71,7 +71,16 @@ require 'axlsx/workbook/worksheet/worksheet.rb' # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used. @@date1904 = false - + + # lets come back to this later when we are ready for parsing. + #def self.parse entry + # io = entry.get_input_stream + # w = self.new + # w.parser_xml = Nokogiri::XML(io.read) + # w.parse_string :date1904, "//xmlns:workbookPr/@date1904" + # w + #end + # Creates a new Workbook # @option options [Boolean] date1904 def initialize(options={}) |
