lib/psd/node_root.rb in psd-1.5.0 vs lib/psd/node_root.rb in psd-2.0.0
- old
+ new
@@ -5,10 +5,11 @@
class Root < PSD::Node
include PSD::HasChildren
include PSD::Node::ParseLayers
attr_accessor :children
+ attr_reader :psd
# Stores a reference to the parsed PSD and builds the
# tree hierarchy.
def initialize(psd)
@psd = psd
@@ -19,29 +20,36 @@
def to_hash
{
children: children.map(&:to_hash),
document: {
width: document_width,
- height: document_height
+ height: document_height,
+ resources: {
+ layer_comps: @psd.layer_comps,
+ guides: @psd.guides,
+ slices: @psd.slices
+ }
}
}
end
# Returns the width and height of the entire PSD document.
def document_dimensions
- [@psd.header.width, @psd.header.height]
+ [document_width, document_height]
end
# The width of the full PSD document as defined in the header.
def document_width
@psd.header.width.to_i
end
+ alias_method :width, :document_width
# The height of the full PSD document as defined in the header.
def document_height
@psd.header.height.to_i
end
+ alias_method :height, :document_height
# The root node has no name since it's not an actual layer or group.
def name
nil
end
@@ -49,10 +57,15 @@
# The depth of the root node is always 0.
def depth
0
end
- def psd; @psd; end
+ [:top, :right, :bottom, :left].each do |meth|
+ define_method(meth) { 0 }
+ end
+
+ def opacity; 255; end
+ def fill_opacity; 255; end
private
def build_hierarchy
@children = []
\ No newline at end of file