candle 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.md +4 -0
  3. data/VERSION +1 -0
  4. data/bin/candle +21 -0
  5. data/lib/candle.rb +68 -0
  6. data/lib/candle/command.rb +27 -0
  7. data/lib/candle/generators/actions.rb +183 -0
  8. data/lib/candle/generators/blank.rb +127 -0
  9. data/lib/candle/generators/cli.rb +55 -0
  10. data/lib/candle/generators/help.rb +47 -0
  11. data/lib/candle/generators/jam.rb +80 -0
  12. data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
  13. data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
  14. data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
  15. data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
  16. data/lib/candle/generators/lua/wax/bin/hammer +157 -0
  17. data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
  18. data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
  19. data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
  20. data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
  21. data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
  22. data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
  23. data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
  24. data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
  25. data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
  26. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
  27. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
  28. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
  29. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
  30. data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
  31. data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
  32. data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
  33. data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
  34. data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
  35. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
  36. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
  37. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
  38. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
  39. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
  40. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
  41. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
  42. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
  43. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
  44. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
  45. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
  46. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
  47. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
  48. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
  49. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
  50. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
  51. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
  52. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
  53. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
  54. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
  55. data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
  56. data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
  57. data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
  58. data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
  59. data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
  60. data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
  61. data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
  62. data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
  63. data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
  64. data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
  65. data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
  66. data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
  67. data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
  68. data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
  69. data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
  70. data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
  71. data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
  72. data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
  73. data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
  74. data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
  75. data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
  76. data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
  77. data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
  78. data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
  79. data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
  80. data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
  81. data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
  82. data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
  83. data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
  84. data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
  85. data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
  86. data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
  87. data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
  88. data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
  89. data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
  90. data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
  91. data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
  92. data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
  93. data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
  94. data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
  95. data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
  96. data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
  97. data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
  98. data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
  99. data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
  100. data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
  101. data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
  102. data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
  103. data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
  104. data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
  105. data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
  106. data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
  107. data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
  108. data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
  109. data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
  110. data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
  111. data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
  112. data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
  113. data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
  114. data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
  115. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
  116. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
  117. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
  118. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
  119. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
  120. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
  121. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
  122. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
  123. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
  124. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
  125. data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
  126. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
  127. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
  128. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
  129. data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
  130. data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
  131. data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
  132. data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
  133. data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
  134. data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
  135. data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
  136. data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
  137. data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
  138. data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
  139. data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
  140. data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
  141. data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
  142. data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
  143. data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
  144. data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
  145. data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
  146. data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
  147. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
  148. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  149. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  150. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
  151. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
  152. data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
  153. data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
  154. data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
  155. data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
  156. data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
  157. data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
  158. data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
  159. data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
  160. data/lib/candle/tasks.rb +22 -0
  161. data/lib/candle/utility.rb +30 -0
  162. data/lib/candle/version.rb +9 -0
  163. data/lib/candle/view.rb +48 -0
  164. metadata +582 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Eiffel Qiu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ candle
2
+ ======
3
+
4
+ Candle is a rubygem for wax iOS framework which writes iOS application in lua.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'rubygems'
5
+ require 'rubygems' unless defined?(Gem)
6
+ require 'thread'
7
+
8
+ class Object
9
+ alias sh system
10
+ end
11
+
12
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
13
+ unless $LOAD_PATH.include?(lib_dir)
14
+ $LOAD_PATH << lib_dir
15
+ end
16
+
17
+ require 'candle'
18
+
19
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/candle/generators/cli')
20
+
21
+ Candle::Generators::Cli.start(ARGV)
@@ -0,0 +1,68 @@
1
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'candle'))
2
+ unless $LOAD_PATH.include?(lib_dir)
3
+ $LOAD_PATH << lib_dir
4
+ end
5
+
6
+ require 'thread'
7
+ require 'candle/version'
8
+ require 'candle/tasks'
9
+ require 'active_support'
10
+
11
+ module Candle
12
+ ##
13
+ # This method return the correct location of mvc-gen bin or
14
+ # exec it using Kernel#system with the given args
15
+ #
16
+ def self.bin_gen(*args)
17
+ @_mvc_gen_bin ||= [IphoneMvc.ruby_command, File.expand_path("../bin/candle", __FILE__)]
18
+ args.empty? ? @_mvc_gen_bin : system(args.unshift(@_mvc_gen_bin).join(" "))
19
+ end
20
+
21
+ ##
22
+ # This module it's used for register generators
23
+ #
24
+ module Generators
25
+
26
+ DEV_PATH = File.expand_path("../../", File.dirname(__FILE__))
27
+
28
+ class << self
29
+
30
+ ##
31
+ # Here we store our generators paths
32
+ #
33
+ def load_paths
34
+ @_files ||= []
35
+ end
36
+
37
+ ##
38
+ # Return a ordered list of task with their class
39
+ #
40
+ def mappings
41
+ @_mappings ||= ActiveSupport::OrderedHash.new
42
+ end
43
+
44
+ ##
45
+ # Gloabl add a new generator class
46
+ #
47
+ def add_generator(name, klass)
48
+ mappings[name] = klass
49
+ end
50
+
51
+ ##
52
+ # Load Global Actions and Component Actions then all files in +load_path+.
53
+ #
54
+ def load_components!
55
+ require 'candle/generators/actions'
56
+ load_paths.flatten.each { |file| require file }
57
+ end
58
+ end
59
+ end # Generators
60
+ end # Candle
61
+
62
+ ##
63
+ # We add our generators to Candle::Genererator
64
+ #
65
+ Candle::Generators.load_paths << Dir[File.dirname(__FILE__) + '/candle/generators/{blank,help}.rb']
66
+
67
+
68
+
@@ -0,0 +1,27 @@
1
+ require 'rbconfig'
2
+
3
+ module Candle
4
+ ##
5
+ # This method return the correct location of candle bin or
6
+ # exec it using Kernel#system with the given args
7
+ #
8
+ def self.bin(*args)
9
+ @_candle_bin ||= [self.ruby_command, File.expand_path("../../../bin/candle", __FILE__)]
10
+ args.empty? ? @_candle_bin : system(args.unshift(@_candle_bin).join(" "))
11
+ end
12
+
13
+ ##
14
+ # Return the path to the ruby interpreter taking into account multiple
15
+ # installations and windows extensions.
16
+ #
17
+ def self.ruby_command
18
+ @ruby_command ||= begin
19
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
20
+ ruby << Config::CONFIG['EXEEXT']
21
+
22
+ # escape string in case path to ruby executable contain spaces.
23
+ ruby.sub!(/.*\s.*/m, '"\&"')
24
+ ruby
25
+ end
26
+ end
27
+ end # Candle
@@ -0,0 +1,183 @@
1
+ module Candle
2
+ module Generators
3
+ class AppRootNotFound < RuntimeError; end
4
+
5
+ module Actions
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ # Performs the necessary generator for a given component choice
12
+ # execute_component_setup(:mock, 'rr')
13
+ def execute_component_setup(component, choice)
14
+ return true && say("Skipping generator for #{component} component...", :yellow) if choice.to_s == 'none'
15
+ say "Applying '#{choice}' (#{component})...", :yellow
16
+ apply_component_for(choice, component)
17
+ send("setup_#{component}") if respond_to?("setup_#{component}")
18
+ end
19
+
20
+ # Returns the related module for a given component and option
21
+ # generator_module_for('rr', :mock)
22
+ def apply_component_for(choice, component)
23
+ # I need to override Thor#apply because for unknow reason :verobse => false break tasks.
24
+ path = File.expand_path(File.dirname(__FILE__) + "/components/#{component.to_s.pluralize}/#{choice}.rb")
25
+ say_status :apply, "#{component.to_s.pluralize}/#{choice}"
26
+ shell.padding += 1
27
+ instance_eval(open(path).read)
28
+ shell.padding -= 1
29
+ end
30
+
31
+ # Returns the component choice stored within the .component file of an application
32
+ # fetch_component_choice(:mock)
33
+ def fetch_component_choice(component)
34
+ retrieve_component_config(destination_root('.components'))[component]
35
+ end
36
+
37
+ # Set the component choice and store it in the .component file of the application
38
+ # store_component_choice(:renderer, :haml)
39
+ def store_component_choice(key, value)
40
+ path = destination_root('.components')
41
+ config = retrieve_component_config(path)
42
+ config[key] = value
43
+ create_file(path, :force => true) { config.to_yaml }
44
+ value
45
+ end
46
+
47
+ # Loads the component config back into a hash
48
+ # i.e retrieve_component_config(...) => { :mock => 'rr', :test => 'riot', ... }
49
+ def retrieve_component_config(target)
50
+ YAML.load_file(target)
51
+ end
52
+
53
+ # Prompts the user if necessary until a valid choice is returned for the component
54
+ # resolve_valid_choice(:mock) => 'rr'
55
+ def resolve_valid_choice(component)
56
+ available_string = self.class.available_choices_for(component).join(", ")
57
+ choice = options[component]
58
+ until valid_choice?(component, choice)
59
+ say("Option for --#{component} '#{choice}' is not available.", :red)
60
+ choice = ask("Please enter a valid option for #{component} (#{available_string}):")
61
+ end
62
+ choice
63
+ end
64
+
65
+ # Returns true if the option passed is a valid choice for component
66
+ # valid_option?(:mock, 'rr')
67
+ def valid_choice?(component, choice)
68
+ choice.present? && self.class.available_choices_for(component).include?(choice.to_sym)
69
+ end
70
+
71
+ # Creates a component_config file at the destination containing all component options
72
+ # Content is a yamlized version of a hash containing component name mapping to chosen value
73
+ def store_component_config(destination)
74
+ components = @_components || options
75
+ create_file(destination) do
76
+ self.class.component_types.inject({}) { |result, comp|
77
+ result[comp] = components[comp].to_s; result
78
+ }.to_yaml
79
+ end
80
+ end
81
+
82
+ # Returns the root for this thor class (also aliased as destination root).
83
+ def destination_root(*paths)
84
+ File.expand_path(File.join(@destination_stack.last, paths))
85
+ end
86
+
87
+ # Returns true if inside a Wax iOS application
88
+ def in_app_root?
89
+ #File.exist?(destination_root('Classes'))
90
+ Dir.glob("tiapp.xml").count >= 1
91
+ end
92
+
93
+ # Returns the field with an unacceptable name(for symbol) else returns nil
94
+ def invalid_fields(fields)
95
+ results = fields.select { |field| field.split(":").first =~ /\W/ }
96
+ results.empty? ? nil : results
97
+ end
98
+
99
+ # Returns the app_name for the application at root
100
+ def fetch_app_name(app='app')
101
+ app_path = destination_root(app, 'app.rb')
102
+ @app_name ||= File.read(app_path).scan(/class\s(.*?)\s</).flatten[0]
103
+ end
104
+
105
+ # Ask something to the user and receives a response.
106
+ #
107
+ # ==== Example
108
+ #
109
+ # ask("What is your app name?")
110
+ def ask(statement, default=nil, color=nil)
111
+ default_text = default ? " (leave blank for #{default}):" : nil
112
+ say("#{statement}#{default_text} ", color)
113
+ result = $stdin.gets.strip
114
+ result.blank? ? default : result
115
+ end
116
+
117
+ # Raise SystemExit if the app is iexistent
118
+ def check_app_existence(app)
119
+ unless File.exist?(destination_root(app))
120
+ say
121
+ say "================================================================="
122
+ say "We didn't found #{app.underscore.camelize}! "
123
+ say "================================================================="
124
+ say
125
+ # raise SystemExit
126
+ end
127
+ end
128
+
129
+ # Ensure that project name is valid, else raise an NameError
130
+ def valid_constant?(name)
131
+ if name =~ /^\d/
132
+ raise ::NameError, "Project name #{name} cannot start with numbers"
133
+ elsif name =~ /^\W/
134
+ raise ::NameError, "Project name #{name} cannot start with non-word character"
135
+ end
136
+ end
137
+
138
+ ## Detect command and dump it's path
139
+ def which cmd
140
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
141
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
142
+ exts.each { |ext|
143
+ exe = "#{path}/#{cmd}#{ext}"
144
+ return exe if File.executable? exe
145
+ }
146
+ end
147
+ return nil
148
+ end
149
+
150
+ module ClassMethods
151
+ # Defines a class option to allow a component to be chosen and add to component type list
152
+ # Also builds the available_choices hash of which component choices are supported
153
+ # component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda]
154
+ def component_option(name, caption, options = {})
155
+ (@component_types ||= []) << name # TODO use ordered hash and combine with choices below
156
+ (@available_choices ||= Hash.new)[name] = options[:choices]
157
+ description = "The #{caption} component (#{options[:choices].join(', ')}, none)"
158
+ class_option name, :default => options[:default] || options[:choices].first, :aliases => options[:aliases], :desc => description
159
+ end
160
+
161
+ # Tell to Candle that for this Thor::Group is necessary a task to run
162
+ def require_arguments!
163
+ @require_arguments = true
164
+ end
165
+
166
+ # Return true if we need an arguments for our Thor::Group
167
+ def require_arguments?
168
+ @require_arguments
169
+ end
170
+
171
+ # Returns the compiled list of component types which can be specified
172
+ def component_types
173
+ @component_types
174
+ end
175
+
176
+ # Returns the list of available choices for the given component (including none)
177
+ def available_choices_for(component)
178
+ @available_choices[component] + [:none]
179
+ end
180
+ end
181
+ end # Actions
182
+ end # Generators
183
+ end # Candle
@@ -0,0 +1,127 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'cli-colorize'
4
+ require 'hirb'
5
+ require File.dirname(__FILE__) + '/jam'
6
+ require File.dirname(__FILE__) + '/../view'
7
+
8
+ module Candle
9
+ module Generators
10
+ class Blank < Jam
11
+ include CLIColorize
12
+
13
+ CLIColorize.default_color = :red
14
+ author 'Eiffel Qiu'
15
+ homepage 'http://www.likenote.com'
16
+ email 'eiffelqiu@gmail.com'
17
+ version Candle::Version::STRING
18
+
19
+ # Add this generator to our candle
20
+ Candle::Generators.add_generator(:blank, self)
21
+
22
+ init_generator
23
+
24
+ desc "Description:\n\n\tcandle will generates an new wax iOS application"
25
+
26
+ argument :name, :desc => "The name of your wax application"
27
+
28
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
29
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
30
+
31
+ def create_project
32
+ valid_constant?(options[:project] || name)
33
+ @project_name = (options[:app] || name).gsub(/\W/, "_").downcase
34
+ @class_name = (options[:app] || name).gsub(/\W/, "_").capitalize
35
+ @developer = "#{`whoami`.strip}"
36
+ @created_on = Date.today.to_s
37
+ self.destination_root = options[:root]
38
+ project = options[:project]
39
+ self.behavior = :revoke if options[:destroy]
40
+
41
+ puts colorize( "Candle Version: #{Candle::Version::STRING}", { :foreground => :red, :background => :white, :config => :underline } )
42
+ puts
43
+
44
+ eval(File.read(__FILE__) =~ /^__END__\n/ && $' || '')
45
+ say (<<-TEXT).gsub(/ {10}/,'')
46
+
47
+ =================================================================
48
+ Your #{@project_name} wax application has been generated.
49
+ Open #{@project_name}.xcodeproj
50
+ Build and Run
51
+ =================================================================
52
+
53
+ TEXT
54
+ end
55
+ end # Project
56
+ end # Generators
57
+ end # Candle
58
+
59
+ __END__
60
+ empty_directory "#{@project_name}"
61
+
62
+ directory "lua/scripts", "#{@project_name}/scripts"
63
+ directory "lua/wax", "#{@project_name}/wax"
64
+
65
+ directory "templates/blank/WaxApplication.xcodeproj", "#{@project_name}/#{@project_name}.xcodeproj"
66
+
67
+ fileName = "#{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/project.pbxproj"
68
+ aFile = File.open(fileName, "r")
69
+ aString = aFile.read
70
+ aFile.close
71
+ aString.gsub!('WaxApplication', "#{@project_name}")
72
+ File.open(fileName, "w") { |file| file << aString }
73
+
74
+ fileName = "#{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/xcuserdata/#{`whoami`.strip}.xcuserdatad/xcschemes/WaxApplication.xcscheme"
75
+ aFile = File.open(fileName, "r")
76
+ aString = aFile.read
77
+ aFile.close
78
+ aString.gsub!('WaxApplication', "#{@project_name}")
79
+ File.open(fileName, "w") { |file| file << aString }
80
+
81
+ fileName = "#{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/xcuserdata/#{`whoami`.strip}.xcuserdatad/xcschemes/xcschememanagement.plist"
82
+ aFile = File.open(fileName, "r")
83
+ aString = aFile.read
84
+ aFile.close
85
+ aString.gsub!('WaxApplication', "#{@project_name}")
86
+ File.open(fileName, "w") { |file| file << aString }
87
+
88
+ fileName = "#{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/xcuserdata/#{`whoami`.strip}.xcuserdatad/xcschemes/WaxApplication.xcscheme"
89
+ aFile = File.open(fileName, "r")
90
+ aString = aFile.read
91
+ aFile.close
92
+ aString.gsub!('WaxApplication', "#{@project_name}")
93
+ File.open(fileName, "w") { |file| file << aString }
94
+
95
+ fileName = "#{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/project.xcworkspace/contents.xcworkspacedata"
96
+ aFile = File.open(fileName, "r")
97
+ aString = aFile.read
98
+ aFile.close
99
+ aString.gsub!('WaxApplication', "#{@project_name}")
100
+ File.open(fileName, "w") { |file| file << aString }
101
+
102
+
103
+
104
+ system "mv #{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad #{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/project.xcworkspace/xcuserdata/#{`whoami`.strip}.xcuserdatad" unless #{`whoami`.strip} != 'eiffel'
105
+
106
+
107
+ system "mv #{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/xcuserdata/eiffel.xcuserdatad #{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/xcuserdata/#{`whoami`.strip}.xcuserdatad" unless #{`whoami`.strip} != 'eiffel'
108
+
109
+ fileName = "#{options[:root]}/#{@project_name}/#{@project_name}.xcodeproj/project.xcworkspace/xcuserdata/#{`whoami`.strip}.xcuserdatad/UserInterfaceState.xcuserstate"
110
+ aFile = File.open(fileName, "r")
111
+ aString = aFile.read.unpack("C*").pack("U*")
112
+ aFile.close
113
+ aString.gsub!('WaxApplication', "#{@project_name}")
114
+ File.open(fileName, "w") { |file| file << aString }
115
+
116
+ template "templates/blank/WaxApplication/main.m.tt", "#{@project_name}/#{@project_name}/main.m"
117
+ template "templates/blank/WaxApplication/ProtocolLoader.h", "#{@project_name}/#{@project_name}/ProtocolLoader.h"
118
+
119
+ directory "templates/blank/WaxApplication/en.lproj", "#{@project_name}/#{@project_name}/en.lproj"
120
+ template "templates/blank/WaxApplication/Default.png", "#{@project_name}/#{@project_name}/Default.png"
121
+ template "templates/blank/WaxApplication/Default@2x.png", "#{@project_name}/#{@project_name}/Default@2x.png"
122
+ template "templates/blank/WaxApplication/Default-568h@2x.png", "#{@project_name}/#{@project_name}/Default-568h@2x.png"
123
+
124
+ template "templates/blank/WaxApplication/WaxApplication-Info.plist.tt", "#{@project_name}/#{@project_name}/#{@project_name}-Info.plist"
125
+ template "templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt", "#{@project_name}/#{@project_name}/#{@project_name}-Prefix.pch"
126
+
127
+ system "chmod 777 #{@project_name}/wax/lib/build-scripts/*"