class Psd2Html

Constants

CONVERTING_MAP

Public Class Methods

new(psdPath,dstHtmlPath) click to toggle source
# File lib/psd2html.rb, line 19
      def initialize(psdPath,dstHtmlPath)
  @dstHtmlPath = dstHtmlPath
              psd = PSD.new(psdPath)
              psd.parse! 
              blockRoot = psd.tree
              rootConvertor = get_convertor(blockRoot,1)
              @treeRoot = format_tree(rootConvertor)
  Until.log("start generate psd tree....")
end

Public Instance Methods

render() click to toggle source
# File lib/psd2html.rb, line 38
  def render
        return <<-STR
                        <meta charset="utf-8" />
                        <style type="text/css">
                        #{@treeRoot.render_css}
                        </style>
                        #{@treeRoot.render_html}
                STR

  end
render_css() click to toggle source
# File lib/psd2html.rb, line 29
def render_css
  Until.log("start render css....")
      return @treeRoot.render_css
end
render_html() click to toggle source
# File lib/psd2html.rb, line 33
def render_html
  Until.log("start render html....")
      return @treeRoot.render_html
end

Protected Instance Methods

format_tree(convertor) click to toggle source
# File lib/psd2html.rb, line 77
def format_tree(convertor)
        if convertor.psNode.has_children?
                convertor.psNode.children.each_with_index do |node,index|
                        childConvertor = get_convertor(node,index)
                        if childConvertor
                                childConvertor.parentConvertor = convertor
                                convertor.childrenConvertors << format_tree(childConvertor)
                        end
                end
        end
        convertor
end
get_convertor(node,index) click to toggle source
# File lib/psd2html.rb, line 63
  def get_convertor(node,index)

          return CONVERTING_MAP["root"].new(node,index,@dstHtmlPath) if node.root? 

          #return unless node.name.include?("|")
#if node.name.include?("|")
  #convertorName = node.name.split('|').last.to_s
#end
          convertorName = get_convertorname(node)
          unless CONVERTING_MAP.include?(convertorName)
                  return
          end
          CONVERTING_MAP[convertorName].new(node,index,@dstHtmlPath)
          end
get_convertorname(node) click to toggle source
# File lib/psd2html.rb, line 50
def get_convertorname(node)
  type = node.to_hash[:type]
  if node.name.include?("|")
    convertorName = node.name.split('|').last.to_s
  elsif type == :group
    convertorName = "block"
  elsif type == :layer && !node.text.nil?
    convertorName = "text"
  else
    convertorName = "img"
  end 
  
end