calatrava 0.0.1

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.
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,2 @@
1
+ source ~/.rvm/scripts/rvm
2
+ rvm rvmrc load
@@ -0,0 +1,17 @@
1
+ local:
2
+ api_endpoint : "http://localhost:8081"
3
+ web_port : 8888
4
+
5
+ development:
6
+ api_endpoint : "http://localhost:8081"
7
+ web_port : 8888
8
+
9
+ test:
10
+ api_endpoint : "http://localhost:8081"
11
+ web_port : 8888
12
+
13
+ automation:
14
+ api_endpoint : "http://localhost:8081"
15
+ web_port : 8889
16
+
17
+ production:
@@ -0,0 +1,7 @@
1
+ root = exports ? this
2
+ root.tw = root.tw ? {}
3
+ tw = root.tw
4
+ tw.bridge = tw.bridge ? {}
5
+
6
+ tw.bridge.environment = () ->
7
+ serviceEndpoint: "<%= configuration['service_endpoint'] %>"
@@ -0,0 +1,33 @@
1
+ LoadModule ssl_module <%=MODULES_PATH%>/mod_ssl.so
2
+ LoadModule proxy_module <%=MODULES_PATH%>/mod_proxy.so
3
+ LoadModule proxy_http_module <%=MODULES_PATH%>/mod_proxy_http.so
4
+ LoadModule headers_module <%=MODULES_PATH%>/mod_headers.so
5
+ <% if LOAD_LOG_MODULE %>
6
+ LoadModule log_config_module <%=MODULES_PATH%>/mod_log_config.so
7
+ <% end %>
8
+ LoadModule mime_module <%=MODULES_PATH%>/mod_mime.so
9
+ LoadModule dir_module <%=MODULES_PATH%>/mod_dir.so
10
+ LoadModule alias_module <%=MODULES_PATH%>/mod_alias.so
11
+
12
+ ErrorLog "logs/error.log"
13
+ LogLevel Debug
14
+
15
+ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"" combined
16
+ CustomLog "logs/access.log" combined
17
+
18
+ PidFile logs/httpd.pid
19
+ LockFile logs/run.lock
20
+
21
+ TypesConfig conf/mime.types
22
+
23
+ Listen <%= configuration['web_port'] %>
24
+
25
+ ProxyRequests off
26
+
27
+ ProxyPass /api <%= configuration['api_endpoint'] %>/api
28
+
29
+ SSLProxyEngine On
30
+
31
+ DocumentRoot "public"
32
+
33
+ DirectoryIndex index.html
@@ -0,0 +1,130 @@
1
+ tw ?= {}
2
+ tw.bridge = tw.bridge ? {}
3
+
4
+ generateRandomString = () ->
5
+ str = ''
6
+ for i in [1...32]
7
+ r = Math.floor(Math.random() * 16)
8
+ str = str + r.toString(16)
9
+ str.toUpperCase()
10
+
11
+ tw.bridge.dispatchEvent = (page, event) ->
12
+ extraArgs = _.toArray(arguments).slice(1);
13
+ tw.bridge.pages.pageNamed(page).dispatch.apply(tw.bridge.pages.pageNamed(page), extraArgs)
14
+
15
+ class tw.bridge.Page
16
+ constructor: (@pageName) ->
17
+ @handlerRegistry = {}
18
+
19
+ bind: (event, handler) ->
20
+ @handlerRegistry[event] = handler
21
+ # Register that an event handler has been installed?
22
+
23
+ dispatch: (event) ->
24
+ args = _.toArray(arguments).slice(1)
25
+ if @handlerRegistry[event]?
26
+ @handlerRegistry[event].apply(this, args)
27
+
28
+ get: (field) ->
29
+ String(pageRegistry.getValueForField(@pageName, field))
30
+
31
+ render: (viewObject) ->
32
+ viewObject = JSON.stringify(viewObject)
33
+ pageRegistry.renderPage(@pageName, viewObject)
34
+
35
+
36
+ tw.bridge.changePage = (target) ->
37
+ pageRegistry.changePage(target)
38
+ target
39
+
40
+ tw.bridge.pages = (() ->
41
+ pagesByName = {}
42
+
43
+ pageNamed: (pageName) ->
44
+ if (!pagesByName[pageName])
45
+ pagesByName[pageName] = new tw.bridge.Page(pageName)
46
+ pagesByName[pageName]
47
+ )()
48
+
49
+ tw.bridge.widgets = (()->
50
+ callbacks = {}
51
+ display: (name, options, callback) ->
52
+ pageRegistry.displayWidget(name, JSON.stringify(options))
53
+ callbacks[name] = callback
54
+
55
+ invokeCallback: (name) ->
56
+ args = _.toArray(arguments).slice(1)
57
+ callbacks[name].apply(this, args)
58
+ )()
59
+
60
+ tw.bridge.dialog = (()->
61
+ display : (name) ->
62
+ pageRegistry.displayDialog(name)
63
+ )()
64
+
65
+ tw.bridge.request = (reqOptions) ->
66
+ tw.bridge.requests.issue reqOptions
67
+
68
+ tw.bridge.requests = (() ->
69
+ successHandlers = {}
70
+ failureHandlers = {}
71
+
72
+ issue: (options) ->
73
+ requestId = generateRandomString()
74
+ if options.body
75
+ bodyStr = options.body
76
+ else
77
+ bodyStr = ""
78
+ if (bodyStr.constructor != String)
79
+ bodyStr = JSON.stringify(body)
80
+
81
+ if options.customHeaders
82
+ headers = JSON.stringify(options.customHeaders)
83
+ else
84
+ headers = ""
85
+
86
+ successHandlers[requestId] = options.success
87
+ failureHandlers[requestId] = options.failure
88
+ ajaxRequestManagerRegistry.makeRequest(requestId,
89
+ options.url,
90
+ options.method,
91
+ bodyStr,
92
+ headers)
93
+
94
+ successfulResponse: (reqId, response) ->
95
+ successHandlers[reqId](response)
96
+ @clearHandlers(reqId)
97
+
98
+ failureResponse: (reqId, errorCode, response) ->
99
+ failureHandlers[reqId](errorCode, response)
100
+ @clearHandlers(reqId)
101
+
102
+ clearHandlers: (reqId) ->
103
+ successHandlers[reqId] = null
104
+ failureHandlers[reqId] = null
105
+ )()
106
+
107
+ tw.bridge.alert = (message) ->
108
+ pageRegistry.alert(message)
109
+
110
+ tw.bridge.openUrl = (url) ->
111
+ pageRegistry.openUrl(url)
112
+
113
+ tw.bridge.trackEvent = (pageName, channel, eventName, variables, properties) ->
114
+ pageRegistry.track(pageName, channel, eventName, variables, properties)
115
+
116
+ tw.bridge.timers = (() ->
117
+ callbacks = {}
118
+
119
+ start: (timeout, callback) ->
120
+ timerId = generateRandomString()
121
+ callbacks[timerId] = callback
122
+ pageRegistry.startTimer(timeout, timerId)
123
+ timerId
124
+
125
+ fireTimer: (timerId) ->
126
+ callbacks[timerId]() if callbacks[timerId]
127
+
128
+ clearTimer: (timerId) ->
129
+ delete callbacks[timerId]
130
+ )()
@@ -0,0 +1,48 @@
1
+ <project name="ivy" xmlns:ivy="antlib:org.apache.ivy.ant">
2
+
3
+ <!-- here is the version of ivy we will use. change this property to try a newer
4
+ version if you want -->
5
+ <property name="ivy.install.version" value="2.3.0-rc1" />
6
+ <property name="ivy.jar.dir" value="${basedir}/ivy" />
7
+ <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
8
+
9
+ <property name="build.dir" value="build" />
10
+ <property name="src.dir" value="src" />
11
+
12
+
13
+ <target name="download-ivy" unless="skip.download">
14
+ <mkdir dir="${ivy.jar.dir}"/>
15
+ <!-- download Ivy from web site so that it can be used even without any special installation -->
16
+ <echo message="installing ivy..."/>
17
+ <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
18
+ dest="${ivy.jar.file}" usetimestamp="true"/>
19
+ </target>
20
+
21
+ <target name="install-ivy" depends="download-ivy" description="--> install ivy">
22
+ <path id="ivy.lib.path">
23
+ <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
24
+ </path>
25
+ <taskdef resource="org/apache/ivy/ant/antlib.xml"
26
+ uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
27
+ </target>
28
+
29
+ <target name="resolve"
30
+ depends="install-ivy"
31
+ description="--> retrieve dependencies with ivy">
32
+ <ivy:configure />
33
+ <ivy:resolve file="${ivy.dep.file}" conf="${ivy.configurations}" />
34
+
35
+ <ivy:report />
36
+
37
+ <ivy:retrieve pattern="libs/[artifact]-[revision](-[classifier]).[ext]" conf="${ivy.configurations}" />
38
+ </target>
39
+
40
+ <target name="clean-ivy" description="--> clean the ivy installation">
41
+ <delete dir="${ivy.jar.dir}"/>
42
+ </target>
43
+
44
+ <target name="clean-cache" depends="install-ivy"
45
+ description="--> clean the ivy cache">
46
+ <ivy:cleancache />
47
+ </target>
48
+ </project>
@@ -0,0 +1,91 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- A standard Android ant build file, with changes to support calatrava.
3
+ It incorporates ivy to manage dependencies. -->
4
+ <project name="test" default="help">
5
+
6
+ <!-- The local.properties file is created and updated by the 'android' tool.
7
+ It contains the path to the SDK. It should *NOT* be checked into
8
+ Version Control Systems. -->
9
+ <property file="local.properties" />
10
+
11
+ <!-- The ant.properties file can be created by you. It is only edited by the
12
+ 'android' tool to add properties to it.
13
+ This is the place to change some Ant specific build properties.
14
+ Here are some properties you may want to change/update:
15
+
16
+ source.dir
17
+ The name of the source directory. Default is 'src'.
18
+ out.dir
19
+ The name of the output directory. Default is 'bin'.
20
+
21
+ For other overridable properties, look at the beginning of the rules
22
+ files in the SDK, at tools/ant/build.xml
23
+
24
+ Properties related to the SDK location or the project target should
25
+ be updated using the 'android' tool with the 'update' action.
26
+
27
+ This file is an integral part of the build system for your
28
+ application and should be checked into Version Control Systems.
29
+
30
+ -->
31
+ <property file="ant.properties" />
32
+
33
+ <!-- The project.properties file is created and updated by the 'android'
34
+ tool, as well as ADT.
35
+
36
+ This contains project specific properties such as project target, and library
37
+ dependencies. Lower level build properties are stored in ant.properties
38
+ (or in .classpath for Eclipse projects).
39
+
40
+ This file is an integral part of the build system for your
41
+ application and should be checked into Version Control Systems. -->
42
+ <loadproperties srcFile="project.properties" />
43
+
44
+ <!-- quick check on sdk.dir -->
45
+ <fail
46
+ message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
47
+ unless="sdk.dir"
48
+ />
49
+
50
+ <!-- Load the calatrava additions -->
51
+ <import file="ant/calatrava.xml" />
52
+
53
+ <!-- Calatrava configuration -->
54
+ <target name="-pre-build" depends="resolve">
55
+ </target>
56
+
57
+ <!-- extension targets. Uncomment the ones where you want to do custom work
58
+ in between standard targets -->
59
+ <!--
60
+ <target name="-pre-compile">
61
+ </target>
62
+
63
+ /* This is typically used for code obfuscation.
64
+ Compiled code location: ${out.classes.absolute.dir}
65
+ If this is not done in place, override ${out.dex.input.absolute.dir} */
66
+ <target name="-post-compile">
67
+ </target>
68
+ -->
69
+
70
+ <!-- Import the actual build file.
71
+
72
+ To customize existing targets, there are two options:
73
+ - Customize only one target:
74
+ - copy/paste the target into this file, *before* the
75
+ <import> task.
76
+ - customize it to your needs.
77
+ - Customize the whole content of build.xml
78
+ - copy/paste the content of the rules files (minus the top node)
79
+ into this file, replacing the <import> task.
80
+ - customize to your needs.
81
+
82
+ ***********************
83
+ ****** IMPORTANT ******
84
+ ***********************
85
+ In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
86
+ in order to avoid having your file be overridden by tools such as "android update project"
87
+ -->
88
+ <!-- version-tag: 1 -->
89
+ <import file="${sdk.dir}/tools/ant/build.xml" />
90
+
91
+ </project>
@@ -0,0 +1,8 @@
1
+ <ivy-module version="2.0">
2
+ <info organisation="com.example" module="currency-converter" revision="0.1" />
3
+ <dependencies>
4
+ <!-- Calatrava dependencies -->
5
+ <dependency org="org.mozilla" name="rhino" rev="1.7R4" conf="*->*,!sources,!javadoc" />
6
+ <dependency org="org.codehaus.jackson" name="jackson-mapper-asl" rev="1.9.8"/>
7
+ </dependencies>
8
+ </ivy-module>
@@ -0,0 +1,12 @@
1
+ <ivysettings>
2
+ <property name="repo.dir" value="/var/ivy"/>
3
+ <resolvers>
4
+ <ibiblio name="maven2" m2compatible="true" />
5
+
6
+ <chain name="chained" returnFirst="true">
7
+ <resolver ref="maven2" />
8
+ </chain>
9
+ </resolvers>
10
+
11
+ <settings defaultResolver="chained" />
12
+ </ivysettings>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ package="com.{{ project_name }}"
4
+ android:versionCode="1"
5
+ android:versionName="1.0">
6
+ <application android:label="@string/app_name" >
7
+ <activity android:name="com.{{ project_name }}.{{ project_title }}"
8
+ android:label="@string/app_name">
9
+ <intent-filter>
10
+ <action android:name="android.intent.action.MAIN" />
11
+ <category android:name="android.intent.category.LAUNCHER" />
12
+ </intent-filter>
13
+ </activity>
14
+ <activity android:name=".ConversionForm"
15
+ android:label="@string/app_name">
16
+ </activity>
17
+ <service android:enabled="true"
18
+ android:name="com.calatrava.bridge.RhinoService"/>
19
+ </application>
20
+ </manifest>
@@ -0,0 +1,27 @@
1
+ package com.{{ project_name }};
2
+
3
+ import com.calatrava.CalatravaPage;
4
+ import com.calatrava.shell.WebViewActivity;
5
+
6
+ import java.util.ArrayList;
7
+ import java.util.Arrays;
8
+ import java.util.List;
9
+
10
+ @CalatravaPage(name = "conversionForm")
11
+ public class ConversionForm extends WebViewActivity
12
+ {
13
+ @Override
14
+ protected String getPageName() {
15
+ return "conversionForm";
16
+ }
17
+
18
+ @Override
19
+ protected List<String> getEvents() {
20
+ return Arrays.asList("selectedInCurrency", "selectedOutCurrency");
21
+ }
22
+
23
+ @Override
24
+ protected List<String> getFields() {
25
+ return new ArrayList<String>();
26
+ }
27
+ }
@@ -0,0 +1,23 @@
1
+ package com.{{ project_name }};
2
+
3
+ import android.app.Activity;
4
+ import android.os.Bundle;
5
+
6
+ import com.calatrava.bridge.Launcher;
7
+
8
+ public class {{ project_title }} extends Activity
9
+ {
10
+ /** Called when the activity is first created. */
11
+ @Override
12
+ public void onCreate(Bundle savedInstanceState)
13
+ {
14
+ super.onCreate(savedInstanceState);
15
+ setContentView(R.layout.main);
16
+
17
+ Launcher.launchKernel("com.test", this, getApplication(), new Runnable() {
18
+ public void run() {
19
+ Launcher.launchFlow("example.converter.start");
20
+ }
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,13 @@
1
+ package com.calatrava;
2
+
3
+ import java.lang.annotation.Target;
4
+ import java.lang.annotation.ElementType;
5
+ import java.lang.annotation.Retention;
6
+ import java.lang.annotation.RetentionPolicy;
7
+
8
+ @Target(ElementType.TYPE)
9
+ @Retention(RetentionPolicy.RUNTIME)
10
+ public @interface CalatravaPage
11
+ {
12
+ String name();
13
+ }
@@ -0,0 +1,166 @@
1
+ package com.calatrava.bridge;
2
+
3
+ import android.content.Context;
4
+ import android.content.Intent;
5
+ import android.os.AsyncTask;
6
+ import android.util.Log;
7
+ import com.calatrava.bridge.RhinoService;
8
+ import org.apache.http.Header;
9
+ import org.apache.http.HttpEntity;
10
+ import org.apache.http.HttpResponse;
11
+ import org.apache.http.StatusLine;
12
+ import org.apache.http.client.HttpClient;
13
+ import org.apache.http.client.methods.HttpGet;
14
+ import org.apache.http.client.methods.HttpPost;
15
+ import org.apache.http.client.methods.HttpRequestBase;
16
+ import org.apache.http.client.methods.HttpUriRequest;
17
+ import org.apache.http.conn.ConnectTimeoutException;
18
+ import org.apache.http.entity.StringEntity;
19
+ import org.apache.http.impl.client.DefaultHttpClient;
20
+ import org.apache.http.message.BasicHeader;
21
+ import org.apache.http.params.HttpConnectionParams;
22
+ import org.json.JSONException;
23
+ import org.json.JSONObject;
24
+
25
+ import java.io.*;
26
+ import java.net.SocketTimeoutException;
27
+ import java.util.Iterator;
28
+
29
+ public class AjaxRequestManager {
30
+
31
+ private static String TAG = AjaxRequestManager.class.getSimpleName();
32
+ private static AjaxRequestManager sharedManager;
33
+ private Context context;
34
+ private RhinoService rhino;
35
+
36
+ public AjaxRequestManager(Context context, RhinoService rhino) {
37
+ this.context = context;
38
+ this.rhino = rhino;
39
+ }
40
+
41
+ public void makeRequest(String requestId, String url, String method, String body, String customHeaders) {
42
+ Log.d(TAG, "requestId is :" + requestId);
43
+ Log.d(TAG, "URL is :" + url);
44
+ Log.d(TAG, "method :" + method);
45
+ Log.d(TAG, "body :" + body);
46
+ Log.d(TAG, "custom headers :" + customHeaders);
47
+
48
+ new AjaxRequest().execute(requestId, url, method, body, customHeaders);
49
+ }
50
+
51
+ private HttpRequestBase httpMethod(String url, String method) {
52
+ return method.equals("post") ? new HttpPost(url) : new HttpGet(url);
53
+ }
54
+
55
+ public static AjaxRequestManager sharedManager() {
56
+ return sharedManager;
57
+ }
58
+
59
+ public static void setSharedManager(AjaxRequestManager ajaxRequestManager) {
60
+ Log.d(TAG, "Set shared manager");
61
+ sharedManager = ajaxRequestManager;
62
+ }
63
+
64
+ class AjaxRequest extends AsyncTask<String, Void, Void> {
65
+
66
+ public static final int CONNECTION_TIMEOUT = 5;
67
+ public static final int SO_TIMEOUT = 60;
68
+
69
+ @Override
70
+ protected Void doInBackground(String... params) {
71
+ String requestId = params[0];
72
+ String url = params[1];
73
+ String method = params[2];
74
+ String body = params[3];
75
+ String customHeaders = params[4];
76
+ try {
77
+ Log.d(TAG, "About to show loader");
78
+ context.sendBroadcast(new Intent("com.calatrava.ajax.start"));
79
+ Log.d(TAG, "Issuing request");
80
+ HttpClient httpclient = new DefaultHttpClient();
81
+ HttpResponse response;
82
+ HttpUriRequest request;
83
+
84
+ if(method.equals("GET")) {
85
+ request = new HttpGet(url);
86
+ } else {
87
+ HttpPost httpPost = new HttpPost(url);
88
+ httpPost.setEntity(new StringEntity(body));
89
+ httpPost.setHeaders(addHeaders(customHeaders));
90
+ request = httpPost;
91
+ }
92
+
93
+ HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), CONNECTION_TIMEOUT * 1000);
94
+ HttpConnectionParams.setSoTimeout(httpclient.getParams(), SO_TIMEOUT * 1000);
95
+ response = httpclient.execute(request);
96
+
97
+ StatusLine statusLine = response.getStatusLine();
98
+ String responseBody = readResponseBody(response);
99
+ Log.d(TAG, "Response is :" + statusLine.getStatusCode());
100
+ Log.d(TAG, "Response is :" + responseBody);
101
+ if (statusLine.getStatusCode() < 300) {
102
+ Log.d(TAG, "Invoke success callback");
103
+ rhino.invokeSuccessCallback(requestId, responseBody);
104
+ } else {
105
+ Log.d(TAG, "Invoke failure callback");
106
+ rhino.invokeFailureCallback(requestId, statusLine.getStatusCode(), responseBody);
107
+ }
108
+ } catch (UnsupportedEncodingException e) {
109
+ Log.d(TAG, "Unable to construct an entity.", e);
110
+ } catch (IOException e) {
111
+ Log.d(TAG, "Request threw exception", e);
112
+ Log.d(TAG, "requestId: " + requestId);
113
+ rhino.invokeFailureCallback(requestId, 500, "IOException");
114
+ } finally {
115
+ Log.d(TAG, "About to hide loader");
116
+ context.sendBroadcast(new Intent("com.calatrava.ajax.finish"));
117
+ }
118
+ return null;
119
+ }
120
+
121
+ private Header[] addHeaders(String customHeaders) {
122
+ Header[] headers = null;
123
+ try {
124
+ if (customHeaders != null && customHeaders.trim() != "") {
125
+ JSONObject jsonCustomHeaders = new JSONObject(customHeaders);
126
+ headers = new Header[jsonCustomHeaders.length()];
127
+ Iterator<String> keys = jsonCustomHeaders.keys();
128
+ int cnt = 0;
129
+ while (keys.hasNext()) {
130
+
131
+ String headerKey = keys.next();
132
+ String headerVal = jsonCustomHeaders.getString(headerKey);
133
+ headers[cnt] = new BasicHeader(headerKey, headerVal);
134
+ cnt++;
135
+ }
136
+ }
137
+ } catch (JSONException e) {
138
+ }
139
+ if (headers != null) {
140
+ Log.d(TAG, "Headers are: " + headers);
141
+ for (Header header : headers) {
142
+ Log.d(TAG, header.getName() + ":" + header.getValue());
143
+ }
144
+ }
145
+ return headers;
146
+ }
147
+
148
+ private String readResponseBody(HttpResponse response) {
149
+ StringBuilder builder = new StringBuilder();
150
+ try {
151
+ HttpEntity entity = response.getEntity();
152
+ InputStream content = entity.getContent();
153
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content), 1024);
154
+ String line;
155
+ while ((line = reader.readLine()) != null) {
156
+ builder.append(line);
157
+ }
158
+
159
+ } catch (Exception e) {
160
+ Log.d(TAG, "Error ");
161
+ e.printStackTrace();
162
+ }
163
+ return builder.toString();
164
+ }
165
+ }
166
+ }
@@ -0,0 +1,17 @@
1
+ package com.calatrava.bridge;
2
+
3
+ import android.content.Context;
4
+
5
+ import java.io.*;
6
+
7
+ public class AssetRepository {
8
+ private Context appContext;
9
+
10
+ public AssetRepository(Context appContext) {
11
+ this.appContext = appContext;
12
+ }
13
+
14
+ public Reader assetReader(String path) throws IOException {
15
+ return new BufferedReader(new InputStreamReader(appContext.getAssets().open(path)), 8192);
16
+ }
17
+ }
@@ -0,0 +1,25 @@
1
+ package com.calatrava.bridge;
2
+
3
+ import java.io.IOException;
4
+
5
+ public class KernelBridge {
6
+
7
+ private AssetRepository assetRepository;
8
+ private RhinoService rhinoService;
9
+
10
+ public KernelBridge(AssetRepository assetRepository, RhinoService rhinoService) throws IOException {
11
+ this.assetRepository = assetRepository;
12
+ this.rhinoService = rhinoService;
13
+
14
+ //load js libraries
15
+ loadLibrary("hybrid/scripts/underscore.js");
16
+
17
+ //load bridge
18
+ loadLibrary("hybrid/scripts/env.js");
19
+ loadLibrary("hybrid/scripts/bridge.js");
20
+ }
21
+
22
+ public void loadLibrary(String libraryName) throws IOException {
23
+ rhinoService.load(assetRepository.assetReader(libraryName), libraryName);
24
+ }
25
+ }