puer 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/puer +2 -54
- data/lib/puer.rb +64 -0
- data/lib/puer/command.rb +27 -0
- data/lib/puer/config.rb +12 -7
- data/lib/puer/generators/actions.rb +183 -0
- data/lib/puer/generators/cli.rb +70 -0
- data/lib/puer/generators/controller.rb +66 -0
- data/lib/puer/generators/gist.rb +247 -0
- data/lib/puer/generators/gist.yml +43 -0
- data/lib/puer/generators/help.rb +82 -0
- data/lib/puer/generators/jam.rb +80 -0
- data/lib/puer/generators/model.rb +65 -0
- data/lib/puer/generators/search.rb +94 -0
- data/lib/puer/generators/templates/controller.tt +9 -0
- data/lib/puer/generators/templates/model.tt +13 -0
- data/lib/puer/generators/templates/view.tt +12 -0
- data/lib/puer/generators/xib.rb +69 -0
- data/lib/puer/session.rb +28 -17
- data/lib/puer/tasks.rb +22 -0
- data/lib/puer/tasks/plugin.rb +73 -0
- data/lib/puer/utility.rb +30 -0
- data/lib/puer/version.rb +9 -0
- data/lib/puer/view.rb +48 -0
- metadata +22 -3
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'cli-colorize'
|
3
|
+
require 'hirb'
|
4
|
+
require File.dirname(__FILE__) + '/../view'
|
5
|
+
require File.dirname(__FILE__) + '/jam'
|
6
|
+
|
7
|
+
module Puer
|
8
|
+
module Generators
|
9
|
+
class Model < Jam
|
10
|
+
include CLIColorize
|
11
|
+
|
12
|
+
CLIColorize.default_color = :red
|
13
|
+
author 'Eiffel Qiu'
|
14
|
+
homepage 'http://www.likenote.com'
|
15
|
+
email 'eiffelqiu@gmail.com'
|
16
|
+
version Puer::Version::STRING
|
17
|
+
|
18
|
+
# Add this generator to our appjam
|
19
|
+
Puer::Generators.add_generator(:model, self)
|
20
|
+
|
21
|
+
init_generator
|
22
|
+
|
23
|
+
desc "Description:\n\n\tpuer will generates an new Model for titanium"
|
24
|
+
|
25
|
+
argument :name, :desc => "The name of your titanium model"
|
26
|
+
|
27
|
+
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
28
|
+
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
29
|
+
|
30
|
+
def create_model
|
31
|
+
if in_app_root?
|
32
|
+
valid_constant?(options[:model] || name)
|
33
|
+
@model_name = (options[:model] || name).gsub(/\W/, "_").downcase
|
34
|
+
@class_name = (options[:model] || name).gsub(/\W/, "_").capitalize
|
35
|
+
@developer = "#{`whoami`.strip}"
|
36
|
+
@created_on = Date.today.to_s
|
37
|
+
self.destination_root = options[:root]
|
38
|
+
self.behavior = :revoke if options[:destroy]
|
39
|
+
|
40
|
+
puts colorize( "Puer Version: #{Puer::Version::STRING}", { :foreground => :red, :background => :white, :config => :underline } )
|
41
|
+
puts
|
42
|
+
eval(File.read(__FILE__) =~ /^__END__\n/ && $' || '')
|
43
|
+
|
44
|
+
say (<<-TEXT).gsub(/ {10}/,'')
|
45
|
+
|
46
|
+
=================================================================
|
47
|
+
Your [#{@model_name.capitalize}] Model has been generated.
|
48
|
+
Build and Run
|
49
|
+
=================================================================
|
50
|
+
|
51
|
+
TEXT
|
52
|
+
else
|
53
|
+
puts
|
54
|
+
puts '-'*70
|
55
|
+
puts "You are not in a titanium project folder"
|
56
|
+
puts '-'*70
|
57
|
+
puts
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end # Model
|
61
|
+
end # Generators
|
62
|
+
end # Puer
|
63
|
+
|
64
|
+
__END__
|
65
|
+
template "templates/model.tt" , "Resources/models/#{@model_name}.js"
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'cli-colorize'
|
3
|
+
require 'thor/group'
|
4
|
+
require 'hirb'
|
5
|
+
require File.dirname(__FILE__) + '/../view'
|
6
|
+
require File.dirname(__FILE__) + '/jam'
|
7
|
+
|
8
|
+
module Puer
|
9
|
+
module Generators
|
10
|
+
class Search < Jam
|
11
|
+
include CLIColorize
|
12
|
+
|
13
|
+
CLIColorize.default_color = :red
|
14
|
+
RENDER_OPTIONS = { :fields => [:category,:command,:description] }
|
15
|
+
|
16
|
+
# Add this generator to our puer
|
17
|
+
Puer::Generators.add_generator(:search, self)
|
18
|
+
|
19
|
+
# Define the source root
|
20
|
+
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
21
|
+
def self.banner; "puer search [option]"; end
|
22
|
+
|
23
|
+
# Include related modules
|
24
|
+
include Thor::Actions
|
25
|
+
include Puer::Generators::Actions
|
26
|
+
|
27
|
+
desc "Description:\n\n\tpuer will search option"
|
28
|
+
|
29
|
+
argument :name, :desc => "The name of option"
|
30
|
+
|
31
|
+
def in_app_root?
|
32
|
+
# File.exist?('Classes')
|
33
|
+
Dir.glob("tiapp.xml").count >= 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_search
|
37
|
+
valid_constant?(options[:search] || name)
|
38
|
+
@gist_name = (options[:app] || name).gsub(/W/, "_").downcase
|
39
|
+
@gist_class_name = (options[:app] || name).gsub(/W/, "_").capitalize
|
40
|
+
@developer = "eiffel"
|
41
|
+
@created_on = Date.today.to_s
|
42
|
+
self.destination_root = options[:root]
|
43
|
+
puts colorize( "Puer Version: #{Puer::Version::STRING}", { :foreground => :red, :background => :white, :config => :underline } )
|
44
|
+
puts
|
45
|
+
require 'yaml'
|
46
|
+
# begin
|
47
|
+
# page_source = Net::HTTP.get(URI.parse("http://eiffelqiu.github.com/puer/gist.yml"))
|
48
|
+
# rescue SocketError => e
|
49
|
+
# end
|
50
|
+
# begin
|
51
|
+
# g = YAML::load(page_source)
|
52
|
+
# rescue ArgumentError => e
|
53
|
+
# g = YAML.load_file(File.expand_path(File.dirname(__FILE__) + '/gist.yml'))
|
54
|
+
# end
|
55
|
+
gistfile = File.expand_path("~") + '/.puer/gist.yml'
|
56
|
+
Gist::update_gist unless File.exist?(gistfile)
|
57
|
+
begin
|
58
|
+
g = YAML.load_file(gistfile)
|
59
|
+
rescue ArgumentError => e
|
60
|
+
g = YAML.load_file(File.expand_path(File.dirname(__FILE__) + '/gist.yml'))
|
61
|
+
end
|
62
|
+
gitopt = []
|
63
|
+
puts "notice: a new version '#{g['info']}' released" if g['info'] and g['info'].strip != "#{Puer::Version::STRING}"
|
64
|
+
puts
|
65
|
+
puts colorize("Available Options contains [#{@gist_name}]")
|
66
|
+
puts
|
67
|
+
g.each_pair {|key,value|
|
68
|
+
# puts colorize("Gist Category [#{key.gsub('_',' ')}]")
|
69
|
+
gname = key.gsub('_',' ')
|
70
|
+
unless key.downcase.strip == 'info'
|
71
|
+
g[key].each { |k|
|
72
|
+
k.each_pair { |k1,v1|
|
73
|
+
gist_name = k1.downcase
|
74
|
+
gist_desc = k[k1][2]['description'].downcase
|
75
|
+
if gist_name.include?(@gist_name) or gist_desc.include?(@gist_name)
|
76
|
+
# gitopt << {:category => "#{key.gsub('_',' ')}", :command => "puer gist #{k1}", :description => "#{k[k1][2]['description']}" }
|
77
|
+
if gname == 'lib'
|
78
|
+
gitopt << {:category => "#{key.gsub('_',' ')}", :command => "puer lib #{k1}", :description => "#{k[k1][2]['description']}" }
|
79
|
+
else
|
80
|
+
gitopt << {:category => "#{key.gsub('_',' ')}", :command => "puer gist #{k1}", :description => "#{k[k1][2]['description']}" }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
}
|
87
|
+
View.render(gitopt, RENDER_OPTIONS)
|
88
|
+
puts
|
89
|
+
end
|
90
|
+
|
91
|
+
end # Search
|
92
|
+
end # Generators
|
93
|
+
end # Puer
|
94
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
var <%= @class_name %> = Model.extend({
|
2
|
+
_fields: {id: Number #{fields_sql}},
|
3
|
+
|
4
|
+
find: function(id) {
|
5
|
+
var model = new #{model}(this.db, this._find(id));
|
6
|
+
return model;
|
7
|
+
},
|
8
|
+
|
9
|
+
item_from: function(row) {
|
10
|
+
var model = new<%= @class_name %>(this.db, this._item_from(row));
|
11
|
+
return model;
|
12
|
+
}
|
13
|
+
});
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'cli-colorize'
|
3
|
+
require 'thor/group'
|
4
|
+
require 'hirb'
|
5
|
+
require File.dirname(__FILE__) + '/../view'
|
6
|
+
require File.dirname(__FILE__) + '/jam'
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/../converters'
|
9
|
+
require File.dirname(__FILE__) + '/../nodes'
|
10
|
+
require File.dirname(__FILE__) + '/../session'
|
11
|
+
require File.dirname(__FILE__) + '/../xibtoti'
|
12
|
+
require File.dirname(__FILE__) + '/../config'
|
13
|
+
|
14
|
+
module Puer
|
15
|
+
module Generators
|
16
|
+
class Xib < Jam
|
17
|
+
include CLIColorize
|
18
|
+
|
19
|
+
CLIColorize.default_color = :red
|
20
|
+
RENDER_OPTIONS = { :fields => [:category,:command,:description] }
|
21
|
+
|
22
|
+
# Add this generator to our puer
|
23
|
+
Puer::Generators.add_generator(:xib, self)
|
24
|
+
|
25
|
+
# Define the source root
|
26
|
+
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
27
|
+
def self.banner; "puer xib "; end
|
28
|
+
|
29
|
+
# Include related modules
|
30
|
+
include Thor::Actions
|
31
|
+
include Puer::Generators::Actions
|
32
|
+
|
33
|
+
desc "Description:\n\n\tpuer convert xib to js"
|
34
|
+
|
35
|
+
argument :name, :default => ""
|
36
|
+
|
37
|
+
def in_app_root?
|
38
|
+
# File.exist?('Classes')
|
39
|
+
Dir.glob("tiapp.xml").count >= 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_xib
|
43
|
+
Dir.glob(File.join('**','*.xib')).each do |s|
|
44
|
+
puts "#{s} is converted to #{File.basename(s, '.*')}.js "
|
45
|
+
#system "puer #{s} -o #{File.basename(s, '.*')}.js"
|
46
|
+
|
47
|
+
$config.parse_file s
|
48
|
+
if $config.has_errors?
|
49
|
+
puts "Aborted!"
|
50
|
+
puts $config.full_log [:error]
|
51
|
+
else
|
52
|
+
severities = []
|
53
|
+
#severities.unshift :warning if @show_warnings
|
54
|
+
log = $config.full_log severities
|
55
|
+
script = js_comments_for(log) + js_for($config.out)
|
56
|
+
@output_file = "#{File.basename(s, '.*')}.js"
|
57
|
+
File.open(@output_file, 'w') do |file|
|
58
|
+
file.write script
|
59
|
+
end
|
60
|
+
#puts log
|
61
|
+
end
|
62
|
+
end
|
63
|
+
puts
|
64
|
+
end
|
65
|
+
|
66
|
+
end # Xib
|
67
|
+
end # Generators
|
68
|
+
end # Puer
|
69
|
+
|
data/lib/puer/session.rb
CHANGED
@@ -4,22 +4,7 @@ require 'converters'
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'plist'
|
6
6
|
|
7
|
-
|
8
|
-
# The session is created from a config file.
|
9
|
-
|
10
|
-
class Session
|
11
|
-
def initialize(path)
|
12
|
-
@ignore_properties = []
|
13
|
-
@ignore_classes = []
|
14
|
-
@classes = {}
|
15
|
-
@properties = {}
|
16
|
-
@log = []
|
17
|
-
File.open path do |file|
|
18
|
-
eval file.read
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :out
|
7
|
+
module Methods
|
23
8
|
|
24
9
|
def parse_file(file)
|
25
10
|
data = Plist::parse_xml( %x[ibtool #{file} --hierarchy --objects --connections] )
|
@@ -69,7 +54,9 @@ class Session
|
|
69
54
|
end
|
70
55
|
|
71
56
|
def ignore_properties(*names)
|
72
|
-
|
57
|
+
names.to_a.each do |o|
|
58
|
+
@ignore_properties << o if o
|
59
|
+
end if names
|
73
60
|
end
|
74
61
|
|
75
62
|
def ignore_classes(*names)
|
@@ -126,4 +113,28 @@ class Session
|
|
126
113
|
def vector(x, y)
|
127
114
|
MultiConverter.new([x, y], /\{(\d+), (\d+)\}/) {|v| v.to_i}
|
128
115
|
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
# Stores all configurable info on how to translate the xib to JS
|
120
|
+
# The session is created from a config file.
|
121
|
+
|
122
|
+
class Session
|
123
|
+
def initialize(path=nil)
|
124
|
+
@ignore_properties = []
|
125
|
+
@ignore_classes = []
|
126
|
+
@classes = {}
|
127
|
+
@properties = {}
|
128
|
+
@log = []
|
129
|
+
if (path) then
|
130
|
+
File.open path do |file|
|
131
|
+
eval file.read
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
attr_reader :out
|
137
|
+
|
138
|
+
include Methods
|
139
|
+
|
129
140
|
end
|
data/lib/puer/tasks.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Puer
|
2
|
+
|
3
|
+
##
|
4
|
+
# This module it's used for bootstrap with puer rake
|
5
|
+
# thirdy party tasks
|
6
|
+
#
|
7
|
+
# ==== Examples
|
8
|
+
#
|
9
|
+
# Puer::Tasks.files << yourtask.rb
|
10
|
+
# Puer::Tasks.files.concat(Dir["/path/to/all/my/tasks/*.rb"])
|
11
|
+
# Puer::Tasks.files.unshift("yourtask.rb")
|
12
|
+
#
|
13
|
+
module Tasks
|
14
|
+
|
15
|
+
##
|
16
|
+
# Returns a list of files to handle with puer rake
|
17
|
+
#
|
18
|
+
def self.files
|
19
|
+
@files ||= Dir[File.dirname(__FILE__) + "/tasks/**/*.rb"]
|
20
|
+
end
|
21
|
+
end # Tasks
|
22
|
+
end # Puer
|
@@ -0,0 +1,73 @@
|
|
1
|
+
TEMPLATE = <<-BLOCK
|
2
|
+
require File.dirname(__FILE__) + '/jam'
|
3
|
+
|
4
|
+
module Puer
|
5
|
+
module Generators
|
6
|
+
class Template < Jam
|
7
|
+
|
8
|
+
# Add this generator to our puer
|
9
|
+
Puer::Generators.add_generator(:template, self)
|
10
|
+
|
11
|
+
# Define the source template root
|
12
|
+
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
13
|
+
def self.banner; "puer template [name]"; end
|
14
|
+
|
15
|
+
# Include related modules
|
16
|
+
include Thor::Actions
|
17
|
+
include Puer::Generators::Actions
|
18
|
+
|
19
|
+
desc "Description:\\n\\n\\tpuer will generates an new PureMvc Model for iphone"
|
20
|
+
|
21
|
+
argument :name, :desc => "The name of your puremvc model"
|
22
|
+
|
23
|
+
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
24
|
+
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
25
|
+
|
26
|
+
def in_app_root?
|
27
|
+
Dir.glob("tiapp.xml").count >= 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_app
|
31
|
+
valid_constant?(options[:template] || name)
|
32
|
+
@project_name = (options[:app] || name).gsub(/\W/, "_").downcase
|
33
|
+
@class_name = (options[:app] || name).gsub(/\W/, "_").capitalize
|
34
|
+
@developer = "#{`whoami`.strip}"
|
35
|
+
@created_on = Date.today.to_s
|
36
|
+
self.destination_root = options[:root]
|
37
|
+
|
38
|
+
eval(File.read(__FILE__) =~ /^__END__\n/ && $' || '')
|
39
|
+
|
40
|
+
say (<<-TEXT).gsub(/ {10}/,'')
|
41
|
+
|
42
|
+
=================================================================
|
43
|
+
Your template has been generated.
|
44
|
+
=================================================================
|
45
|
+
|
46
|
+
TEXT
|
47
|
+
end
|
48
|
+
|
49
|
+
end # Template
|
50
|
+
end # Generators
|
51
|
+
end # Puer
|
52
|
+
|
53
|
+
__END__
|
54
|
+
# put your template command here
|
55
|
+
|
56
|
+
BLOCK
|
57
|
+
|
58
|
+
namespace :puer do
|
59
|
+
namespace :plugin do
|
60
|
+
|
61
|
+
desc 'Create an plugin structure for puer'
|
62
|
+
task :create do
|
63
|
+
puts "what's your plugin name?"
|
64
|
+
pname = STDIN.gets.chomp
|
65
|
+
plugin_dir = File.dirname(__FILE__) + "/../generators/#{pname}"
|
66
|
+
plugin_name = File.dirname(__FILE__) + "/../generators/#{pname}.rb"
|
67
|
+
Dir.mkdir plugin_dir unless File.exist?(plugin_dir)
|
68
|
+
File.open(plugin_name, 'w') {|f| f.write(TEMPLATE) }
|
69
|
+
end
|
70
|
+
|
71
|
+
end # plugin
|
72
|
+
end # puer
|
73
|
+
|
data/lib/puer/utility.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Puer
|
2
|
+
|
3
|
+
module Utility
|
4
|
+
class XcodeUUIDGenerator
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@num = [Time.now.to_i, Process.pid, getMAC]
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get the ethernet hardware address ("MAC"). This version
|
11
|
+
# works on Mac OS X 10.6 (Snow Leopard); it has not been tested
|
12
|
+
# on other versions.
|
13
|
+
|
14
|
+
def getMAC(interface='en0')
|
15
|
+
addrMAC = `ifconfig #{interface} ether`.split("\n")[1]
|
16
|
+
addrMAC ? addrMAC.strip.split[1].gsub(':','').to_i(16) : 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate
|
20
|
+
@num[0] += 1
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
"%08X%04X%012X" % @num
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end # Puer
|