calatrava 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +9 -0
  2. data/.rvmrc +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +202 -0
  5. data/Plans.md +20 -0
  6. data/README.md +73 -0
  7. data/Rakefile +26 -0
  8. data/bin/calatrava +6 -0
  9. data/calatrava.gemspec +35 -0
  10. data/features/cli.feature +14 -0
  11. data/features/project.feature +48 -0
  12. data/features/step_definitions/template_steps.rb +8 -0
  13. data/features/support/env.rb +5 -0
  14. data/lib/calatrava/app.rb +30 -0
  15. data/lib/calatrava/manifest.rb +44 -0
  16. data/lib/calatrava/project.rb +218 -0
  17. data/lib/calatrava/resources_build_phase.rb +19 -0
  18. data/lib/calatrava/tasks/apache.rb +44 -0
  19. data/lib/calatrava/tasks/artifact.rb +24 -0
  20. data/lib/calatrava/tasks/assets.rb +6 -0
  21. data/lib/calatrava/tasks/automation.rb +38 -0
  22. data/lib/calatrava/tasks/bootstrap.rb +10 -0
  23. data/lib/calatrava/tasks/build.rb +1 -0
  24. data/lib/calatrava/tasks/configuration.rb +41 -0
  25. data/lib/calatrava/tasks/droid.rb +83 -0
  26. data/lib/calatrava/tasks/haml.rb +71 -0
  27. data/lib/calatrava/tasks/ios.rb +73 -0
  28. data/lib/calatrava/tasks/kernel.rb +52 -0
  29. data/lib/calatrava/tasks/precommit.rb +22 -0
  30. data/lib/calatrava/tasks/release.rb +17 -0
  31. data/lib/calatrava/tasks/shell.rb +17 -0
  32. data/lib/calatrava/tasks/web.rb +82 -0
  33. data/lib/calatrava/tasks.rb +93 -0
  34. data/lib/calatrava/template.rb +44 -0
  35. data/lib/calatrava/templates/.rvmrc.calatrava +2 -0
  36. data/lib/calatrava/templates/Gemfile.calatrava +4 -0
  37. data/lib/calatrava/templates/Rakefile +1 -0
  38. data/lib/calatrava/templates/assets/lib/ICanHaz.js +542 -0
  39. data/lib/calatrava/templates/assets/lib/underscore.js +1059 -0
  40. data/lib/calatrava/templates/assets/lib/zepto.js +1355 -0
  41. data/lib/calatrava/templates/build_env.sh +2 -0
  42. data/lib/calatrava/templates/config/environments.yml +17 -0
  43. data/lib/calatrava/templates/config/templates/env.coffee.erb +7 -0
  44. data/lib/calatrava/templates/config/templates/httpd.conf.erb +33 -0
  45. data/lib/calatrava/templates/droid/app/bridge.coffee +130 -0
  46. data/lib/calatrava/templates/droid/calatrava/ant/calatrava.xml +48 -0
  47. data/lib/calatrava/templates/droid/calatrava/calatrava-build.xml +91 -0
  48. data/lib/calatrava/templates/droid/calatrava/ivy.xml +8 -0
  49. data/lib/calatrava/templates/droid/calatrava/ivysettings.xml +12 -0
  50. data/lib/calatrava/templates/droid/calatrava/src/com/CALATRAVA_TMPL/AndroidManifest.xml.calatrava +20 -0
  51. data/lib/calatrava/templates/droid/calatrava/src/com/CALATRAVA_TMPL/ConversionForm.java.calatrava +27 -0
  52. data/lib/calatrava/templates/droid/calatrava/src/com/CALATRAVA_TMPL/Title.java.calatrava +23 -0
  53. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/CalatravaPage.java +13 -0
  54. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/AjaxRequestManager.java +166 -0
  55. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/AssetRepository.java +17 -0
  56. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/KernelBridge.java +25 -0
  57. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/Launcher.java +85 -0
  58. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/PageRegistry.java +225 -0
  59. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/RegisteredActivity.java +86 -0
  60. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/RequestLoader.java +31 -0
  61. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/bridge/RhinoService.java +212 -0
  62. data/lib/calatrava/templates/droid/calatrava/src/com/calatrava/shell/WebViewActivity.java +247 -0
  63. data/lib/calatrava/templates/droid/manifest.yml +1 -0
  64. data/lib/calatrava/templates/ios/Podfile.calatrava +5 -0
  65. data/lib/calatrava/templates/ios/manifest.yml +1 -0
  66. data/lib/calatrava/templates/ios/res/js/bridge.js +249 -0
  67. data/lib/calatrava/templates/ios/res/xibs/ProgressViewController.xib +334 -0
  68. data/lib/calatrava/templates/ios/res/xibs/WebViewController.xib +173 -0
  69. data/lib/calatrava/templates/ios/src/AppDelegate.h +8 -0
  70. data/lib/calatrava/templates/ios/src/AppDelegate.m +56 -0
  71. data/lib/calatrava/templates/ios/src/CALATRAVA_TMPL-Info.plist +45 -0
  72. data/lib/calatrava/templates/ios/src/CALATRAVA_TMPL-Prefix.pch +14 -0
  73. data/lib/calatrava/templates/ios/src/ConversionFormViewController.h +16 -0
  74. data/lib/calatrava/templates/ios/src/ConversionFormViewController.m +179 -0
  75. data/lib/calatrava/templates/ios/src/ConversionFormViewController.xib +357 -0
  76. data/lib/calatrava/templates/ios/src/en.lproj/InfoPlist.strings +2 -0
  77. data/lib/calatrava/templates/ios/src/main.m +10 -0
  78. data/lib/calatrava/templates/ios/test/AJAXConnectionTest.m +21 -0
  79. data/lib/calatrava/templates/ios/test/AppTests-Prefix.pch +8 -0
  80. data/lib/calatrava/templates/ios/test/CalatravaiOSTests-Info.plist +22 -0
  81. data/lib/calatrava/templates/ios/test/TWBridgePageRegistryTest.m +15 -0
  82. data/lib/calatrava/templates/ios/test/en.lproj/InfoPlist.strings +2 -0
  83. data/lib/calatrava/templates/kernel/.gitignore +1 -0
  84. data/lib/calatrava/templates/kernel/app/calatrava.coffee +8 -0
  85. data/lib/calatrava/templates/kernel/app/converter/controller.converter.coffee +50 -0
  86. data/lib/calatrava/templates/kernel/app/converter/init.converter.coffee +11 -0
  87. data/lib/calatrava/templates/kernel/app/pageHelper.coffee +17 -0
  88. data/lib/calatrava/templates/kernel/features/support/bridge.coffee +124 -0
  89. data/lib/calatrava/templates/kernel/features/support/spec_helper.js +49 -0
  90. data/lib/calatrava/templates/kernel/spec/converter/controller.converter.spec.coffee +37 -0
  91. data/lib/calatrava/templates/kernel/spec/environment.spec_helper.coffee +25 -0
  92. data/lib/calatrava/templates/kernel/spec/spec_helper.js +49 -0
  93. data/lib/calatrava/templates/kernel/spec/stubView.coffee +18 -0
  94. data/lib/calatrava/templates/kernel/watchr.rb +17 -0
  95. data/lib/calatrava/templates/package.json +20 -0
  96. data/lib/calatrava/templates/shell/layouts/single_page.haml +23 -0
  97. data/lib/calatrava/templates/shell/pages/converter/conversionForm.haml +12 -0
  98. data/lib/calatrava/templates/shell/pages/converter/page.conversionForm.coffee +42 -0
  99. data/lib/calatrava/templates/shell/shell.scss +1 -0
  100. data/lib/calatrava/templates/shell/support/shell.coffee +21 -0
  101. data/lib/calatrava/templates/web/apache/conf/mime.types +1357 -0
  102. data/lib/calatrava/templates/web/app/source/bridge.coffee +158 -0
  103. data/lib/calatrava/templates/web/app/source/init.coffee +14 -0
  104. data/lib/calatrava/templates/web/app/views/index.haml +18 -0
  105. data/lib/calatrava/templates/web/deploy/instance.sh +10 -0
  106. data/lib/calatrava/templates/web/manifest.yml +1 -0
  107. data/lib/calatrava/version.rb +3 -0
  108. data/lib/calatrava.rb +5 -0
  109. metadata +302 -0
@@ -0,0 +1,218 @@
1
+ require 'mustache'
2
+ require 'yaml'
3
+ require 'xcoder'
4
+ require 'xcodeproj'
5
+
6
+ require 'calatrava/resources_build_phase'
7
+
8
+ module Calatrava
9
+
10
+ class Project
11
+
12
+ def sh(cmd)
13
+ $stdout.puts cmd
14
+ system(cmd)
15
+ end
16
+
17
+ def self.here(directory)
18
+ @@current = Project.new(directory)
19
+ end
20
+
21
+ def self.current
22
+ @@current
23
+ end
24
+
25
+ attr_reader :name
26
+
27
+ def initialize(name, overrides = {})
28
+ @name = name
29
+ @slug = name.gsub(" ", "_").downcase
30
+ @title = @name[0..0].upcase + @name[1..-1]
31
+ @options = {}
32
+ if File.exists?(@name) && File.directory?(@name)
33
+ @path = File.expand_path(@name)
34
+ @options = YAML.load(IO.read(File.join(@name, 'calatrava.yml')))
35
+ @name = @options[:project_name]
36
+ end
37
+ @options.merge! overrides
38
+ end
39
+
40
+ def dev?
41
+ @options[:is_dev]
42
+ end
43
+
44
+ def create(template)
45
+ create_project(template)
46
+ create_directory_tree(template)
47
+ create_files(template)
48
+
49
+ create_android_tree(template)
50
+ create_ios_tree(template)
51
+ end
52
+
53
+ def create_project(template)
54
+ FileUtils.mkdir_p @name
55
+ File.open(File.join(@name, 'calatrava.yml'), "w+") do |f|
56
+ f.print({:project_name => @name}.to_yaml)
57
+ end
58
+ end
59
+
60
+ def target_item(item)
61
+ item.gsub("CALATRAVA_TMPL", @name)
62
+ end
63
+
64
+ def create_directory_tree(template)
65
+ template.walk_directories do |dir|
66
+ FileUtils.mkdir_p(File.join(@name, target_item(dir)))
67
+ end
68
+ end
69
+
70
+ def create_files(template)
71
+ template.walk_files do |file_info|
72
+ target_name = target_item(file_info[:name])
73
+ if File.extname(file_info[:name]) == ".calatrava"
74
+ File.open(File.join(@name, target_name.gsub(".calatrava", "")), "w+") do |f|
75
+ expanded = Mustache.render(IO.read(file_info[:path]),
76
+ :project_name => @name,
77
+ :project_slug => @slug,
78
+ :project_title => @title,
79
+ :dev? => dev?)
80
+ f.print(expanded)
81
+ end
82
+ else
83
+ FileUtils.cp(file_info[:path], File.join(@name, target_name))
84
+ end
85
+ end
86
+ end
87
+
88
+ def create_android_tree(template)
89
+ Dir.chdir(File.join(@name, "droid")) do
90
+ sh "android create project --name '#{@slug}' --path '#{@name}' --package com.#{@slug} --target android-10 --activity #{@title}"
91
+
92
+ Dir.walk("calatrava") do |item|
93
+ target_item = item.sub('calatrava', @name)
94
+ FileUtils.mkdir_p(target_item) if File.directory? item
95
+ FileUtils.cp(item, target_item) if File.file? item
96
+ end
97
+ Dir.chdir "#{@name}" do
98
+ Dir.chdir "src/com/#{@name}" do
99
+ FileUtils.mv "Title.java", "#{@title}.java"
100
+ FileUtils.mv "AndroidManifest.xml", "../../../AndroidManifest.xml"
101
+ end
102
+ FileUtils.mv "calatrava-build.xml", "build.xml"
103
+ end
104
+
105
+ FileUtils.rm_rf "calatrava"
106
+ end
107
+ end
108
+
109
+ def create_ios_project
110
+ Xcodeproj::Project.new.tap do |proj|
111
+ %w{Foundation UIKit CoreGraphics}.each { |fw| proj.add_system_framework fw }
112
+ end
113
+ end
114
+
115
+ def create_ios_project_groups(base_dir, proj, target)
116
+ source_files_for_target = []
117
+
118
+ walker = lambda do |item, group|
119
+ if item.directory?
120
+ group_name = item.basename
121
+ child_group = group.create_group group_name
122
+ item.each_child { |item| walker.call(item, child_group) }
123
+ elsif item.file?
124
+ file_path = item.relative_path_from(base_dir)
125
+ group.create_file file_path.to_s
126
+ source_files_for_target << Xcodeproj::Project::Object::PBXNativeTarget::SourceFileDescription.new(file_path, "", nil)
127
+ else
128
+ raise 'what is it then?!'
129
+ end
130
+ end
131
+ (base_dir + "src").each_child { |item| walker.call(item, proj.main_group) }
132
+ target.add_source_files source_files_for_target
133
+ end
134
+
135
+ def create_ios_folder_references(base_dir, proj, target)
136
+ FileUtils.mkdir_p "ios/public"
137
+ public_folder = proj.main_group.create_file "public"
138
+ public_folder.last_known_file_type = 'folder'
139
+ build_file = public_folder.build_files.new
140
+
141
+ shared_phase = Xcodeproj::Project::Object::PBXResourcesBuildPhase.new(proj,nil,{})
142
+
143
+ shared_phase << build_file
144
+ target.build_phases << shared_phase
145
+
146
+ end
147
+
148
+ def create_ios_project_target(proj)
149
+ target = Xcodeproj::Project::Object::PBXNativeTarget.new(proj,
150
+ nil,
151
+ 'productType' => 'com.apple.product-type.application',
152
+ 'productName' => @name)
153
+
154
+ target.build_configurations.each do |config|
155
+ config.build_settings.merge!(Xcodeproj::Project::Object::XCBuildConfiguration::COMMON_BUILD_SETTINGS[:ios])
156
+
157
+ # E.g. [:ios, :release]
158
+ extra_settings_key = [:ios, config.name.downcase.to_sym]
159
+ if extra_settings = Xcodeproj::Project::Object::XCBuildConfiguration::COMMON_BUILD_SETTINGS[extra_settings_key]
160
+ config.build_settings.merge!(extra_settings)
161
+ end
162
+
163
+ config.build_settings.merge!({
164
+ "GCC_PREFIX_HEADER" => "src/#{@name}-Prefix.pch",
165
+ "OTHER_LDFLAGS" => ['-ObjC', '-all_load'],
166
+ "INFOPLIST_FILE" => "src/#{@name}-Info.plist",
167
+ "SKIP_INSTALL" => "NO",
168
+ "IPHONEOS_DEPLOYMENT_TARGET" => "5.0",
169
+ })
170
+ config.build_settings.delete "DSTROOT"
171
+ config.build_settings.delete "INSTALL_PATH"
172
+
173
+ end
174
+
175
+ calatrava_phase = Xcodeproj::Project::Object::PBXShellScriptBuildPhase.new(proj,nil,{})
176
+ target.build_phase_references.insert(0,calatrava_phase.uuid) # hacky manual way to get build phase inserted in the right place
177
+
178
+ calatrava_phase.name = "Build Calatrava Kernel & Shell"
179
+ calatrava_phase.shell_script = <<-EOS.split("\n").collect(&:strip).join("\n")
180
+ source ${SRCROOT}/../build_env.sh
181
+ bundle exec rake ios:xcode:prebuild
182
+ EOS
183
+
184
+ proj.targets << target
185
+ target
186
+ end
187
+
188
+ def create_ios_tree(template)
189
+ proj = create_ios_project
190
+ base_dir = Pathname.new(@name) + "ios"
191
+
192
+ target = create_ios_project_target(proj)
193
+ create_ios_project_groups(base_dir, proj, target)
194
+ create_ios_folder_references(base_dir, proj, target)
195
+
196
+ proj.save_as (base_dir + "#{@name}.xcodeproj").to_s
197
+ end
198
+
199
+ def modules
200
+ Dir[File.join(@path, 'kernel/app/*')].select { |n| File.directory? n }.collect { |n| File.basename n }
201
+ end
202
+
203
+ def src_paths
204
+ modules.collect { |m| "app/#{m}" }.join(':')
205
+ end
206
+
207
+ def build_ios(options = {})
208
+ proj = Xcode.project("ios/#{@name}.xcworkspace")
209
+ builder = proj.target(@name).config('Debug').builder
210
+ builder.clean
211
+ builder.sdk = options[:sdk] || :iphonesimulator
212
+ builder.build
213
+ builder.package
214
+ end
215
+
216
+ end
217
+
218
+ end
@@ -0,0 +1,19 @@
1
+ require 'xcodeproj'
2
+
3
+ module Xcodeproj
4
+ class Project
5
+ module Object
6
+
7
+ class PBXResourcesBuildPhase < PBXBuildPhase
8
+ has_many :files
9
+
10
+ def initialize(*)
11
+ super
12
+ self.file_references ||= []
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,44 @@
1
+ require 'erb'
2
+
3
+ directory APACHE_LOGS_DIR
4
+
5
+ if `uname -a`.chomp["amzn1"]
6
+ HTTPD = "httpd"
7
+ MODULES_PATH = "/usr/lib64/httpd/modules"
8
+ LOAD_LOG_MODULE = true
9
+ elsif `uname`.chomp == "Linux"
10
+ HTTPD = "apache2"
11
+ MODULES_PATH = "/usr/lib/apache2/modules"
12
+ LOAD_LOG_MODULE = false
13
+ else
14
+ HTTPD = "httpd"
15
+ MODULES_PATH = "/usr/libexec/apache2"
16
+ LOAD_LOG_MODULE = true
17
+ end
18
+
19
+ def httpd(command)
20
+ exec %Q|#{HTTPD} -d #{APACHE_DIR} -f conf/httpd.conf -e DEBUG -k #{command} -DNO_DETACH -DFOREGROUND|
21
+ end
22
+
23
+ def configure_apache
24
+ cp config_path("httpd.conf"), File.join(APACHE_DIR, 'conf')
25
+ end
26
+
27
+ def launch_apache
28
+ puts
29
+ puts "\t\t" + "*"*40
30
+ puts "\t\t" + "*** STARTING APACHE ON PORT 8888 ***"
31
+ puts "\t\t" + "*"*40
32
+ puts
33
+
34
+ httpd :start
35
+ end
36
+
37
+ def stop_apache
38
+ httpd :stop
39
+ end
40
+
41
+ def reload_apache
42
+ httpd :restart
43
+ end
44
+
@@ -0,0 +1,24 @@
1
+ def artifact(path, env = nil)
2
+ artifact_dir = env.nil? ? "artifacts/" : "artifacts/#{env}/"
3
+ mkdir_p artifact_dir
4
+ cp path, artifact_dir, :preserve => true
5
+ end
6
+
7
+ def artifact_dir(source_path, name)
8
+ artifact_dir_path = "artifacts/#{name}/"
9
+ mkdir_p artifact_dir_path
10
+ sh "cp -R #{source_path}/* #{artifact_dir_path}"
11
+ end
12
+
13
+ def artifact_path(sub_path)
14
+ File.join("artifacts", sub_path)
15
+ end
16
+
17
+ namespace :artifact do
18
+
19
+ desc "Removes all pre-existing artifacts"
20
+ task :clean do
21
+ rm_rf "artifacts/*.*"
22
+ end
23
+
24
+ end
@@ -0,0 +1,6 @@
1
+ def coffee(in_dir_or_file, out_dir)
2
+ if !Dir["#{in_dir_or_file}/**/*.coffee"].empty? || File.exists?(in_dir_or_file)
3
+ $stdout.puts "coffee #{in_dir_or_file} -> #{out_dir}"
4
+ sh "node_modules/coffee-script/bin/coffee --compile --output #{out_dir} #{in_dir_or_file}"
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ namespace :automation do
2
+ namespace :web do
3
+ desc "Runs cucumber tests against the web app"
4
+ task :features, [:file] => [:apache_for_features, :create_sim_link, :copy_steps_file, :clean_up_results_dir] do |t, args|
5
+ ENV['PATH'] = "#{ROOT_DIR}/web/features:#{ENV['PATH']}"
6
+ features_to_be_run = args[:file] ? "#{FEATURES_DIR}/#{args[:file]}" : FEATURES_DIR
7
+ sh "cucumber --strict --tags @all,@web --tags ~@wip #{features_to_be_run} --format html --out #{FEATURE_RESULTS_DIR}/report.html --format pretty"
8
+ end
9
+
10
+ desc "launch a daemon apache instance on port 8888 which will serve the features and mock the backend services"
11
+ task :apache_for_features => ['web:build', APACHE_LOGS_DIR] do
12
+ create_plist
13
+ configure_apache
14
+ `launchctl unload #{APACHE_DIR}/com.jenkins.calatrava.apache.plist`
15
+ `launchctl load -w #{APACHE_DIR}/com.jenkins.calatrava.apache.plist`
16
+ `sleep 5`
17
+ end
18
+
19
+ desc "create sim link for the ios step_definitions and support folder"
20
+ task :create_sim_link do
21
+ sh "rm -rf #{FEATURES_DIR}/step_definitions"
22
+ sh "rm -rf #{FEATURES_DIR}/support"
23
+ end
24
+
25
+ desc "copy the web_steps file to web_steps.rb"
26
+ task :copy_steps_file do
27
+ sh "rm -f #{FEATURES_DIR}/*.rb"
28
+ sh "cp #{FEATURES_DIR}/web_steps #{FEATURES_DIR}/web_steps.rb"
29
+ end
30
+
31
+ desc "delete and create the results dir"
32
+ task :clean_up_results_dir do
33
+ sh "rm -rf #{FEATURE_RESULTS_DIR}"
34
+ sh "mkdir #{FEATURE_RESULTS_DIR}"
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,10 @@
1
+ desc "Installs all required Ruby gems and Node.js packages for your new Calatrava project."
2
+ task :bootstrap do
3
+ sh "bundle install"
4
+ sh "npm install"
5
+ cd "ios" do
6
+ sh "pod install"
7
+ end
8
+
9
+ Rake::Task['configure:development'].invoke
10
+ end
@@ -0,0 +1 @@
1
+ task :build => ['web:build', 'ios:build', 'droid:build']
@@ -0,0 +1,41 @@
1
+ def config_for(environment)
2
+ YAML::load(File.open(CONFIG_YAML))[environment]
3
+ end
4
+
5
+ def evaluate_template(template_path, configuration)
6
+ file_path = File.join(CONFIG_RESULT_DIR, File.basename(template_path).gsub(".erb", ''))
7
+ puts "Config: #{File.basename(template_path)} -> #{File.basename(file_path)}"
8
+ result = ERB.new(IO.read(template_path)).result(binding)
9
+ IO.write(file_path, result)
10
+ end
11
+
12
+ def config_path(file)
13
+ env = ENV['CALATRAVA_ENV'] || "development"
14
+ puts "CALATRAVA_ENV = '#{env}'"
15
+ full_path = artifact_path(File.join(env, file))
16
+ fail "Could not find '#{file}' in environment '#{env}'" unless File.exists? full_path
17
+ full_path
18
+ end
19
+
20
+ def app_name
21
+ end
22
+
23
+ TEMPLATES = FileList["#{CONFIG_TEMPLATE_DIR}/*.erb"]
24
+
25
+ namespace :configure do
26
+
27
+ %w{local development test automation production}.each do |environment|
28
+ desc "Create config files for #{environment} environment"
29
+ task environment.to_sym => [:clean, CONFIG_RESULT_DIR] do
30
+ configuration = config_for(environment)
31
+ TEMPLATES.each do |template|
32
+ evaluate_template(template, configuration)
33
+ end
34
+ artifact_dir(CONFIG_RESULT_DIR, environment)
35
+ end
36
+ end
37
+
38
+ task :clean do
39
+ rm_rf CONFIG_RESULT_DIR
40
+ end
41
+ end
@@ -0,0 +1,83 @@
1
+ namespace :droid do
2
+
3
+ version = "1.0"
4
+ droid_manifest = Calatrava::Manifest.new('droid')
5
+
6
+ html_views = droid_manifest.features.collect do |feature|
7
+ html_dir = "droid/#{Calatrava::Project.current.name}/assets/hybrid/views"
8
+ Dir["shell/pages/#{feature}/*.haml"].collect do |page|
9
+ pageName = File.basename(page, '.haml')
10
+ file "#{html_dir}/#{pageName}.html" => page do
11
+ HamlSupport::compile_hybrid_page feature, page, html_dir
12
+ end
13
+ end
14
+ end.flatten
15
+
16
+ desc "Creates html from haml using Android layout"
17
+ task :haml => [CONFIG[:droid][:html]] + html_views
18
+
19
+ desc "Compile droid-specific coffee to javascript"
20
+ task :coffee => CONFIG[:droid][:assets] do
21
+ coffee File.join(CONFIG[:droid][:root], "app"), CONFIG[:droid][:js]
22
+ end
23
+
24
+ desc "Copies required assets for droid"
25
+ task :shared => ["shell:scss", "shell:coffee", "kernel:coffee",
26
+ CONFIG[:droid][:css], CONFIG[:droid][:imgs], CONFIG[:droid][:js],
27
+ :config, CONFIG[:droid][:fonts]] do
28
+ cp_ne "#{BUILD_CORE_CSS_DIR}/*.css", CONFIG[:droid][:css]
29
+ cp_ne "#{ASSETS_IMG_DIR}/*", CONFIG[:droid][:imgs]
30
+ cp_ne "assets/lib/*.js", CONFIG[:droid][:js]
31
+
32
+ droid_manifest.js_files.each do |js_file|
33
+ sh "cp #{js_file} #{CONFIG[:droid][:js]}"
34
+ end
35
+ droid_manifest.load_file("droid/#{Calatrava::Project.current.name}/assets/hybrid", 'hybrid/scripts', :type => :text, :include_pages => false)
36
+
37
+ cp_ne "build/shell/js/**/*.js", CONFIG[:droid][:js]
38
+ cp_ne "build/kernel/js/*.js", CONFIG[:droid][:js]
39
+ cp_ne "#{ASSETS_FONTS_DIR}/*", CONFIG[:droid][:fonts]
40
+ end
41
+
42
+ task :app => [:shared, :haml, :coffee]
43
+
44
+ desc "Prepares config for the app"
45
+ task :config do
46
+ env_coffee = config_path("env.coffee")
47
+ coffee env_coffee, CONFIG[:droid][:js]
48
+ end
49
+
50
+ desc "Builds the complete Android app"
51
+ task :build => [:app, :config, :write_build_number] do
52
+ cd "droid/#{Calatrava::Project.current.name}" do
53
+ sh "ant clean debug"
54
+ end
55
+ end
56
+
57
+ desc "Update the app to show the correct build number"
58
+ task :write_build_number do
59
+ cd "droid/#{Calatrava::Project.current.name}" do
60
+ sh %{cat AndroidManifest.xml | sed -E "s/android:versionName=\".*\"/android:versionName=\\"#{version}\\">/g" > AndroidManifest.xml.new}
61
+ mv "AndroidManifest.xml.new", "AndroidManifest.xml"
62
+ end
63
+ end
64
+
65
+ desc "Publishes the built Android app as an artifact"
66
+ task :publish => :build do
67
+ artifact("droid/#{Calatrava::Project.current.name}/bin/#{Calatrava::Project.current.name}-debug.apk", ENV['CALATRAVA_ENV'])
68
+ end
69
+
70
+ desc "Deploy app to device/emulator"
71
+ task :deploy => :publish do
72
+ sh "adb uninstall com.#{Calatrava::Project.current.name} ; adb install -r artifacts/#{ENV['CALATRAVA_ENV']}/#{Calatrava::Project.current.name}-debug.apk"
73
+ end
74
+
75
+ desc "Clean droid public directory"
76
+ task :clean do
77
+ rm_rf CONFIG[:droid][:public]
78
+ cd "droid/#{Calatrava::Project.current.name}" do
79
+ sh "ant clean"
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,71 @@
1
+ require 'haml'
2
+
3
+ module HamlSupport
4
+
5
+ class Helper
6
+
7
+ attr_reader :page_name
8
+
9
+ def initialize(feature = nil, page = nil)
10
+ @feature = feature
11
+ @page_name = page
12
+ end
13
+
14
+ def content_for(named_chunk)
15
+ chunk = @chunks[named_chunk]
16
+ (chunk && chunk.call) || ""
17
+ end
18
+
19
+ def layout_with(layout_name, content_blocks = {})
20
+ @chunks = content_blocks
21
+ layout_template = IO.read(File.join(SHELL_LAYOUTS_DIR, "#{layout_name}.haml"))
22
+ Haml::Engine.new(layout_template).render(self, {})
23
+ end
24
+
25
+ def render_partial(partial_name, locals = {})
26
+ partial_template = IO.read("#{partial_name}.haml")
27
+ Haml::Engine.new(partial_template).render(self, locals)
28
+ end
29
+
30
+ def render_page(page_name = nil, locals = {})
31
+ page_name = File.join(@feature, @page_name) unless page_name
32
+ page_template = IO.read(File.join('shell/pages', "#{page_name}.haml"))
33
+ Haml::Engine.new(page_template).render(self, locals)
34
+ end
35
+
36
+ end
37
+
38
+ class << self
39
+
40
+ def compile_hybrid_page(feature, page_path, output_path, options = {})
41
+ puts "haml page: #{page_path} -> #{output_path}"
42
+
43
+ options[:helper] = Helper.new(feature, File.basename(page_path, ".haml"))
44
+ options[:template] = "shell/layouts/single_page.haml"
45
+ options[:out] = File.join(output_path, File.basename(page_path, '.*') + '.html')
46
+
47
+ render_haml(options)
48
+ end
49
+
50
+ def compile(haml_path, html_dir, options = {})
51
+ puts "haml: #{haml_path} -> #{html_dir}"
52
+
53
+ options[:helper] ||= Helper.new
54
+ options[:template] = haml_path
55
+ options[:out] = File.join(html_dir, File.basename(haml_path, '.*') + '.html')
56
+
57
+ render_haml(options)
58
+ end
59
+
60
+ def render_haml(options)
61
+ html_path = options[:out]
62
+ template = IO.read(options[:template])
63
+
64
+ html = Haml::Engine.new(template).render(options[:helper])
65
+
66
+ html.gsub!("file:///android_asset/hybrid", "../assets") if options[:platform] == 'ios'
67
+ IO.write(html_path, html)
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,73 @@
1
+ namespace :ios do
2
+
3
+
4
+ ios_manifest = Calatrava::Manifest.new('ios')
5
+
6
+ html_views = ios_manifest.features.collect do |feature|
7
+ html_dir = "ios/public/views"
8
+ Dir["shell/pages/#{feature}/*.haml"].collect do |page|
9
+ pageName = File.basename(page, '.haml')
10
+ file "#{html_dir}/#{pageName}.html" => page do
11
+ HamlSupport::compile_hybrid_page feature, page, html_dir, :platform => 'ios'
12
+ end
13
+ end
14
+ end.flatten
15
+
16
+ desc "Creates html from haml using iPhone layout"
17
+ task :haml => [CONFIG[:ios][:html]] + html_views
18
+
19
+ directory 'ios/public/assets'
20
+
21
+ desc "Copies required assets for ios"
22
+ task :shared => ["shell:scss", "shell:coffee", "kernel:coffee", 'ios/public/assets',
23
+ CONFIG[:ios][:css], CONFIG[:ios][:imgs], CONFIG[:ios][:js], :config, CONFIG[:ios][:fonts]] do
24
+ cp_ne "#{BUILD_CORE_CSS_DIR}/*.css", CONFIG[:ios][:css]
25
+ cp_ne "#{ASSETS_IMG_DIR}/*", CONFIG[:ios][:imgs]
26
+ cp_ne "assets/lib/*.js", CONFIG[:ios][:js]
27
+ cp_ne "ios/res/js/*.js", CONFIG[:ios][:js]
28
+
29
+ ios_manifest.js_files.each do |js_file|
30
+ sh "cp #{js_file} #{CONFIG[:ios][:js]}"
31
+ end
32
+ ios_manifest.load_file('ios/public/assets', '%@/public/assets/scripts', :type => :text, :include_pages => false)
33
+
34
+ cp_ne "build/shell/js/**/*.js", CONFIG[:ios][:js]
35
+ cp_ne "build/kernel/js/*.js", CONFIG[:ios][:js]
36
+ cp_ne "#{ASSETS_FONTS_DIR}/*", CONFIG[:ios][:fonts]
37
+ end
38
+
39
+ task :app => [:shared, :haml]
40
+
41
+ desc "Prepares config for the app"
42
+ task :config do
43
+ env_coffee = config_path("env.coffee")
44
+ coffee env_coffee, CONFIG[:ios][:js]
45
+ end
46
+
47
+ task :configured_app => [:app, :config]
48
+
49
+ desc "Builds the iOS app"
50
+ task :build => :configured_app do
51
+ ENV['CMDLINE_BUILD'] = 'true'
52
+ Calatrava::Project.current.build_ios
53
+ end
54
+
55
+ desc "Publish the iOS app as an artifact"
56
+ task :publish => :build do
57
+ artifact(CONFIG[:ios][:xcode][:package_path], ENV['CALATRAVA_ENV'])
58
+ end
59
+
60
+ desc "Clean ios public directory"
61
+ task :clean do
62
+ sh "rm -rf #{CONFIG[:ios][:public]}/*"
63
+ end
64
+
65
+ namespace :xcode do
66
+ task :prebuild do
67
+ if !ENV['CMDLINE_BUILD']
68
+ Rake::Task['configure:development'].invoke
69
+ Rake::Task['ios:configured_app'].invoke
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,52 @@
1
+ namespace :kernel do
2
+
3
+ directory "build/kernel/js"
4
+
5
+ desc "Build kernel js files"
6
+ task :coffee => "build/kernel/js" do
7
+ coffee "kernel/app", "build/kernel/js"
8
+ end
9
+
10
+ desc "Clean built kernel"
11
+ task :clean do
12
+ rm_rf "build/kernel"
13
+ end
14
+
15
+ file '.node_updated' => 'package.json' do
16
+ sh "npm install"
17
+ sh "touch .node_updated"
18
+ end
19
+
20
+ desc "Run jasmine test. If specs not given in argument, runs all test"
21
+ task :spec => '.node_updated' do |t, args|
22
+ cd "kernel" do
23
+ ENV['NODE_PATH'] = "app:#{Calatrava::Project.current.src_paths}:spec:../assets/lib"
24
+ sh "../node_modules/jasmine-node/bin/jasmine-node --coffee --test-dir spec"
25
+ end
26
+ end
27
+
28
+ desc "Run cucumber.js features for kernel"
29
+ task :features, [:file] => ['.node_updated', :create_sim_link] do |t, args|
30
+ cd "kernel" do
31
+ ENV['NODE_PATH'] = "#{Calatrava::Project.current.src_paths}:features/support:../assets/lib:features/step_definitions:../features/testdata"
32
+ features_to_be_run = args[:file] ? "#{kernel/features}/#{args[:file]}" : "features"
33
+ sh "../node_modules/cucumber/bin/cucumber.js --tags @all,@kernel --tags ~@wip '#{features_to_be_run}'"
34
+ end
35
+ end
36
+
37
+ namespace :features do
38
+ task :wip => ['.node_updated', :create_sim_link] do
39
+ cd "kernel" do
40
+ ENV['NODE_PATH'] = "#{Calatrava::Project.current.src_paths}:features/support:../assets/lib:features/step_definitions:../features/testdata"
41
+ sh "../node_modules/cucumber/bin/cucumber.js --tags @wip --tags @kernel features"
42
+ end
43
+ end
44
+ end
45
+
46
+ desc "create sim link for the kernels step_definitions and support folder"
47
+ task :create_sim_link do
48
+ sh "ln -sFfh kernel/features/step_definitions/ features/step_definitions"
49
+ sh "ln -sFfh kernel/features/support/ features/support"
50
+ end
51
+
52
+ end