Top Level Namespace

Defined Under Namespace

Modules: Methods, Puer Classes: ClassInfo, Converter, MultiConverter, NodeInfo, Session, String

Constant Summary collapse

TEMPLATE =
<<-BLOCK
require File.dirname(__FILE__) + '/jam'

module Puer
  module Generators
    class Template < Jam

      # Add this generator to our puer
      Puer::Generators.add_generator(:template, self)

      # Define the source template root
      def self.source_root; File.expand_path(File.dirname(__FILE__)); end
      def self.banner; "puer template [name]"; end

      # Include related modules
      include Thor::Actions
      include Puer::Generators::Actions            

      desc "Description:\\n\\n\\tpuer will generates an new PureMvc Model for iphone"

      argument :name, :desc => "The name of your puremvc model"

      class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
      class_option :destroy, :aliases => '-d', :default => false,   :type    => :boolean

      def in_app_root?
        Dir.glob("tiapp.xml").count >= 1
      end     

      def create_app
        valid_constant?(options[:template] || name)
        @project_name = (options[:app] || name).gsub(/\W/, "_").downcase
        @class_name = (options[:app] || name).gsub(/\W/, "_").capitalize
        @developer = "#{`whoami`.strip}"
        @created_on = Date.today.to_s
        self.destination_root = options[:root]
                
        eval(File.read(__FILE__) =~ /^__END__\n/ && $' || '')

say (<<-TEXT).gsub(/ {10}/,'')

=================================================================
Your template has been generated.
=================================================================

TEXT          
        end

    end # Template
  end # Generators
end # Puer

__END__
# put your template command here

BLOCK

Instance Method Summary collapse

Instance Method Details

#creation_call(name, class_name, info) ⇒ Object



17
18
19
20
# File 'lib/puer/xibtoti.rb', line 17

def creation_call(name, class_name, info)
  "var #{name} = #{class_name}({\n" +
    info.keys.sort.map {|key| "\t#{key}:#{inline_js_for(info[key])}"}.join(",\n") + "\n});"
end

#inline_js_for(data) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/puer/xibtoti.rb', line 4

def inline_js_for(data)

    case data
    when Hash 
      '{' + data.map {|k,v| "#{k}:#{inline_js_for(v)}"}.join(',') + '}'
    when String 
      "'#{data}'"
    else 
      data.to_s
    end  

end

#js_comments_for(text) ⇒ Object



31
32
33
# File 'lib/puer/xibtoti.rb', line 31

def js_comments_for text
 ""  #text.map {|line| line.chomp.empty? ? line : "// #{line}"}.join + "\n"
end

#js_for(nodes) ⇒ Object



27
28
29
# File 'lib/puer/xibtoti.rb', line 27

def js_for(nodes)
  nodes.map {|node| js_sections_for(node)}.flatten.join("\n\n")
end

#js_sections_for(node) ⇒ Object



22
23
24
25
# File 'lib/puer/xibtoti.rb', line 22

def js_sections_for(node)
  [creation_call(node.name, node.node_class.creation_call, node.properties)] +
    node.subviews.map {|child| [js_sections_for(child), "#{node.name}.add(#{child.name});"]}.flatten
end