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,50 @@
1
+ example ?= {}
2
+ example.converter ?= {}
3
+
4
+ example.converter.controller = ({views, changePage, ajax}) ->
5
+
6
+ currencies = ['USD','AUD','GBP']
7
+ inCurrency = "USD"
8
+ outCurrency = "AUD"
9
+
10
+ currencyDropdownViewMessage = (selectedCurrency,unselectableCurrency) ->
11
+ _.map( currencies, (c) ->
12
+ {
13
+ code: c,
14
+ enabled: c != unselectableCurrency
15
+ selected: c == selectedCurrency
16
+ })
17
+
18
+ renderCurrencyList = ({listName, disabled, selected}) ->
19
+ viewMessage = {}
20
+ viewMessage[listName] = currencyDropdownViewMessage(selected, disabled)
21
+ views.conversionForm.render(viewMessage)
22
+
23
+ renderOutCurrencyList = ()->
24
+ renderCurrencyList
25
+ listName: 'outCurrencies'
26
+ disabled: inCurrency
27
+ selected: outCurrency
28
+
29
+ renderInCurrencyList = ()->
30
+ renderCurrencyList
31
+ listName: 'inCurrencies'
32
+ disabled: outCurrency
33
+ selected: inCurrency
34
+
35
+ views.conversionForm.bind 'convert', ->
36
+ amount = views.conversionForm.get('in_amount')
37
+ start = views.conversionForm.get('in_currency')
38
+ end = views.conversionForm.get('out_currency')
39
+
40
+ views.conversionForm.bind 'selectedInCurrency', (selectedCurrency) ->
41
+ inCurrency = selectedCurrency
42
+ renderOutCurrencyList()
43
+
44
+
45
+ views.conversionForm.bind 'selectedOutCurrency', (selectedCurrency) ->
46
+ outCurrency = selectedCurrency
47
+ renderInCurrencyList()
48
+
49
+ renderInCurrencyList()
50
+ renderOutCurrencyList()
@@ -0,0 +1,11 @@
1
+ example ?= {}
2
+ example.converter ?= {}
3
+
4
+ example.converter.start = ->
5
+ example.converter.controller
6
+ views:
7
+ conversionForm: tw.bridge.pages.pageNamed "conversionForm"
8
+ changePage: tw.bridge.changePage
9
+ ajax: tw.bridge.request
10
+
11
+ tw.bridge.changePage "conversionForm"
@@ -0,0 +1,17 @@
1
+ calatrava.shell ?= {}
2
+
3
+ calatrava.shell.pageHelper = ($page) ->
4
+
5
+ handlers = {}
6
+
7
+ handler: (name, callback) ->
8
+ handlers[name] = callback
9
+
10
+ trigger: (name) -> handlers[name]()
11
+
12
+ reset: ->
13
+ $("#overlay").remove()
14
+
15
+ initialize: ->
16
+ $page.off('click', 'a[data-href]').on 'click', 'a[data-href]', ()->
17
+ handlers['static_link'] $(this).data 'href'
@@ -0,0 +1,124 @@
1
+ tw ?= {}
2
+ tw.bridge = tw.bridge ? {}
3
+
4
+ generateRandomString = () ->
5
+ str = ''
6
+ for i in [0..32]
7
+ r = Math.floor(Math.random() * 16)
8
+ str = str + r.toString(16)
9
+ return str.toUpperCase();
10
+
11
+ tw.bridge.environment = () ->
12
+ serviceEndpoint: "http://localhost:4568"
13
+ apiEndpoint: "http://localhost:4568"
14
+ sessionTimeout: 10
15
+
16
+ tw.bridge.dispatchEvent = (page, event) ->
17
+ tw.bridge.pages.pageNamed(page).dispatch(event)
18
+
19
+ class tw.bridge.Page
20
+ constructor: (@pageName) ->
21
+ @fieldValues = {}
22
+ @handlerRegistry = {}
23
+ @renderObjects = []
24
+
25
+ bind: (event, handler) ->
26
+ @handlerRegistry[event] = handler
27
+
28
+ trigger: (event) ->
29
+ @handlerRegistry[event]()
30
+
31
+ dispatch: (event) ->
32
+ args = _.toArray(arguments).slice(2)
33
+ @handlerRegistry[event].apply(this, args)
34
+
35
+ get: (field) ->
36
+ @fieldValues[field]
37
+
38
+ stubField: (field, value) ->
39
+ @fieldValues[field] = value
40
+
41
+ render: (viewObject) ->
42
+ @renderObjects.push(viewObject)
43
+ that = this
44
+ _.map(viewObject, (value, key) ->
45
+ that.stubField(key, value)
46
+ )
47
+
48
+ lastRender: () ->
49
+ @renderObjects[@renderObjects.length - 1]
50
+
51
+ allRenderObjects: () ->
52
+ @renderObjects
53
+
54
+ tw.bridge.changePage = (target) ->
55
+ tw.bridge.pages.setCurrent(target)
56
+ tw.bridge.changedPage = target
57
+
58
+ tw.bridge.pages = (() ->
59
+ pagesByName = {}
60
+ current = ""
61
+
62
+ pageNamed: (pageName) ->
63
+ if (!pagesByName[pageName])
64
+ pagesByName[pageName] = new tw.bridge.Page(pageName)
65
+ pagesByName[pageName]
66
+
67
+ current: () -> pagesByName[current]
68
+ setCurrent: (newPage) -> current = newPage
69
+ )()
70
+
71
+ class tw.bridge.Widget
72
+ constructor: (@name, @options, @callback) ->
73
+
74
+ getCallback: ->
75
+ @callback
76
+
77
+ getOptions: ->
78
+ @options
79
+
80
+ tw.bridge.widgets = (()->
81
+ widgets = {}
82
+ display: (name, options, callback) ->
83
+ widgets[name] = new tw.bridge.Widget(name, options, callback)
84
+
85
+ widget: (name) ->
86
+ widgets[name]
87
+ )()
88
+
89
+ tw.bridge.timers = (() ->
90
+ timers = {}
91
+ start: (timeout, callback) ->
92
+ timers["searchResultsExpired"] = callback
93
+
94
+ clearTimer: () ->
95
+
96
+ triggerTimer: (name) ->
97
+ timers[name]()
98
+ )()
99
+
100
+ tw.bridge.dialog = (() ->
101
+ display: (name) ->
102
+ )()
103
+
104
+ tw.bridge.request = (reqOptions) ->
105
+ # mock this for kernel features
106
+ response = tw.bridge.requests.issue reqOptions
107
+ if response.status == 'successful'
108
+ reqOptions.success(response.body)
109
+ else
110
+ reqOptions.failure(response.body)
111
+
112
+ tw.bridge.requests = (() ->
113
+ storedRequests = []
114
+
115
+ stubRequest: (options) ->
116
+ storedRequests.push(options)
117
+
118
+ issue: (options) ->
119
+ _.tap _.chain(storedRequests).filter((sr) -> sr.url.test(options.url)).last().value().response, (v) ->
120
+ )()
121
+
122
+ tw.bridge.alert = (message) ->
123
+
124
+ tw.bridge.trackEvent = () ->
@@ -0,0 +1,49 @@
1
+ // This is the only file that adds things to the global namespace. To
2
+ // simulate, in Node, the appearance of running in a browser, with
3
+ // files loaded by <script> tags
4
+
5
+ // Because it needs to pollute the global namespace, it has been
6
+ // written in JavaScript, because CoffeeScript protects the global
7
+ // namespace very effectively.
8
+
9
+ coffee = require('coffee-script')
10
+ sinon = require('sinon');
11
+ should = require('should');
12
+ date = require('date');
13
+
14
+ underscore = require('underscore');
15
+ _ = underscore;
16
+
17
+ exports.tw = require('bridge').tw;
18
+
19
+ function recursiveExtend(moduleToExtend, module) {
20
+ _.each(module, function (value, key) {
21
+ if (moduleToExtend[key] == null) moduleToExtend[key] = {};
22
+ if (typeof value == "Object") {
23
+ recursiveExtend(moduleToExtend[key], value);
24
+ } else {
25
+ _.extend(moduleToExtend[key], module[key]);
26
+ }
27
+ });
28
+ }
29
+
30
+ function getPageObjectForPageName(pageName){
31
+ var pageObject;
32
+ return pageObject;
33
+ }
34
+
35
+ function getWidget(name) {
36
+ return tw.bridge.widgets.widget(name)
37
+ }
38
+
39
+ function showDialog(name) {
40
+ return tw.bridge.dialog.display(name)
41
+ }
42
+
43
+ function triggerTimer(name){
44
+ return tw.bridge.timers.triggerTimer(name)
45
+ }
46
+
47
+ exports.getPageObjectForPageName = getPageObjectForPageName;
48
+ exports.getWidget = getWidget;
49
+ exports.triggerTimer = triggerTimer;
@@ -0,0 +1,37 @@
1
+ exports = require 'spec_helper'
2
+
3
+ example = exports.example
4
+ stubView = exports.stubView
5
+
6
+ describe 'converter controller', ->
7
+ ajax = null
8
+ changePage = null
9
+ views = null
10
+
11
+ beforeEach ->
12
+ ajax = jasmine.createSpy("ajax requester")
13
+ changePage = jasmine.createSpy('page changer').andCallFake (targetPage) ->
14
+ if views[targetPage].boundEvents['pageOpened']?
15
+ views[targetPage].trigger 'pageOpened'
16
+ views =
17
+ conversionForm: stubView.create('converterForm')
18
+
19
+ subject = example.converter.controller
20
+ changePage: changePage
21
+ views: views
22
+ ajax: ajax
23
+
24
+ it 'should bind the convert event', ->
25
+ expect(views.conversionForm.boundEvents['convert']).not.toBeUndefined()
26
+
27
+ describe 'converting', ->
28
+
29
+ beforeEach ->
30
+ views.conversionForm.trigger 'convert'
31
+
32
+ it 'should get the amount to convert', ->
33
+ expect(views.conversionForm.get).toHaveBeenCalledWith('amount')
34
+ it 'should get the starting currency', ->
35
+ expect(views.conversionForm.get).toHaveBeenCalledWith('start_currency')
36
+ it 'should get the ending currency', ->
37
+ expect(views.conversionForm.get).toHaveBeenCalledWith('end_currency')
@@ -0,0 +1,25 @@
1
+ tw ?= {}
2
+
3
+ tw =
4
+ bridge:
5
+ environment: () ->
6
+ serviceEndpoint: "test env"
7
+ sessionTimeout: 10
8
+
9
+ changePage: (page) ->
10
+ page.show()
11
+
12
+ alert: (msg) ->
13
+ console.log("alerting: #{msg}")
14
+
15
+ openUrl: (url) ->
16
+ console.log("launching url: #{url}")
17
+
18
+ timers:
19
+ start: () ->
20
+ clearTimer: () ->
21
+
22
+ dialog:
23
+ display: () ->
24
+
25
+ exports.tw = tw
@@ -0,0 +1,49 @@
1
+ // This is the only file that adds things to the global namespace. To
2
+ // simulate, in Node, the appearance of running in a browser, with
3
+ // files loaded by <script> tags
4
+
5
+ // Because it needs to pollute the global namespace, it has been
6
+ // written in JavaScript, because CoffeeScript protects the global
7
+ // namespace very effectively.
8
+
9
+ sinon = require('sinon');
10
+ underscore = require('underscore');
11
+ _ = underscore;
12
+
13
+ stubView = require('stubView.coffee').stubView;
14
+
15
+ tw = require('environment.spec_helper').tw;
16
+
17
+ function recursiveExtend(moduleToExtend, module) {
18
+ _.each(module, function (value, key) {
19
+ if (moduleToExtend[key] == null) moduleToExtend[key] = {};
20
+ if (typeof value == "Object") {
21
+ recursiveExtend(moduleToExtend[key], value);
22
+ } else {
23
+ _.extend(moduleToExtend[key], module[key]);
24
+ }
25
+ });
26
+ }
27
+
28
+ example = {};
29
+ recursiveExtend(example, require('controller.converter').example);
30
+
31
+ exports.stubView = stubView;
32
+ exports.tw = tw;
33
+ exports.appDir = __dirname + "/../app";
34
+ exports.example = example;
35
+
36
+ // Custom matchers:
37
+ beforeEach(function() {
38
+ this.addMatchers({
39
+ toBeEmpty: function() {
40
+ if (typeof this.actual === "string") {
41
+ return this.actual === "";
42
+ } else if (_.isArray(this.actual)) {
43
+ return _.isEmpty(this.actual);
44
+ } else {
45
+ return this.actual !== null && this.actual !== undefined && !this.actual.isEmpty();
46
+ }
47
+ }
48
+ });
49
+ });
@@ -0,0 +1,18 @@
1
+ stubView ?= {}
2
+
3
+ stubView =
4
+ create: (name) ->
5
+ boundEvents: {}
6
+ trigger: (event) ->
7
+ @boundEvents[event]()
8
+
9
+ bind: (event, handler) ->
10
+ @boundEvents[event] = handler
11
+
12
+ render: (viewObject) ->
13
+
14
+ get: jasmine.createSpy('get')
15
+
16
+ hideErrors: ()->
17
+
18
+ exports.stubView = stubView
@@ -0,0 +1,17 @@
1
+ def notify(message)
2
+ growlnotify = `which growlnotify`.chomp
3
+ if !growlnotify.empty?
4
+ system "#{growlnotify} -m \"#{message}\" loganberry-bb"
5
+ end
6
+ notify_send = `which notify-send`.chomp
7
+ unless notify_send.empty?
8
+ system "#{notify_send} -t 100 'loagnberry-bb' '#{message}'"
9
+ end
10
+ end
11
+
12
+ system("rake kernel:spec")
13
+
14
+ watch('^(app|spec)') do
15
+ system("rake kernel:spec")
16
+ notify ($?.success? ? "Build successful!" : "Build failed :(")
17
+ end
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "kernel-features"
3
+ , "version": "0.0.1"
4
+ , "private": true
5
+ , "dependencies" : {
6
+ "coffee-script" : "1.2.0"
7
+ , "sinon" : "*"
8
+ , "cucumber" : "latest"
9
+ , "jsdom" : "latest"
10
+ , "mime" : "latest"
11
+ , "ws" : "0.4.8"
12
+ , "jasmine-node" : "*"
13
+ , "should" : "*"
14
+ , "underscore" : "*"
15
+ , "jasmine-reporters" : "*"
16
+ , "walkdir" : "*"
17
+ , "request" : "*"
18
+ , "cssom" : "*"
19
+ }
20
+ }
@@ -0,0 +1,23 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ -%w{reset app common device}.each do |filename|
5
+ %link(type="text/css" rel="stylesheet" media="all" href="file:///android_asset/hybrid/styles/#{filename}.css")
6
+
7
+ -%w{env zepto ICanHaz underscore calatrava bridge shell pageHelper}.each do |filename|
8
+ %script(type="text/javascript" src="file:///android_asset/hybrid/scripts/#{filename}.js")
9
+
10
+ :javascript
11
+ $(document).ready(function() {
12
+ window.batSignal = tw.batSignal();
13
+ });
14
+
15
+ %script(src="file:///android_asset/hybrid/scripts/page.#{page_name}.js" type="text/javascript")
16
+ :javascript
17
+ $(document).ready(function() {
18
+ window.#{page_name}View = calatrava.pageView.#{page_name}();
19
+ });
20
+
21
+ %body
22
+ %div#app_container.container
23
+ = render_page
@@ -0,0 +1,12 @@
1
+ %div#conversionForm.page
2
+
3
+ %script#currencyDropdownTmpl(type="text/html")
4
+ {{#currencies}}
5
+ <option value="{{code}}" {{^enabled}}disabled{{/enabled}} {{#selected}}selected{{/selected}}> {{code}} </option>
6
+ {{/currencies}}
7
+
8
+ %h3 THE BEST CURRENCY CONVERTER EVER
9
+ %select.in_currency
10
+ %input.in_amount(type='number' placeholder='amount')
11
+ %select.out_currency
12
+ %button GO
@@ -0,0 +1,42 @@
1
+ calatrava.pageView ?= {}
2
+
3
+ calatrava.pageView.conversionForm = ->
4
+
5
+ #TODO: refactor out
6
+ $page = $('#conversionForm')
7
+ $p = (sel)-> $(sel,$page)
8
+
9
+ eventHandlers = {}
10
+
11
+ trigger = (event, args...) ->
12
+ eventHandlers[event](args...)
13
+
14
+ renderCurrencyDropdown = ($select, currencies)->
15
+ $select.empty().html ich.currencyDropdownTmpl
16
+ currencies: currencies
17
+
18
+ renderSection = (key,data) ->
19
+ switch key
20
+ when 'inCurrencies' then renderCurrencyDropdown( $p('.in_currency'), data )
21
+ when 'outCurrencies' then renderCurrencyDropdown( $p('.out_currency'), data )
22
+ else console.warn( "unrecognized render section #{key}" )
23
+
24
+
25
+ $p(".out_currency").on 'change', ->
26
+ selectedCurrencyCode = $(this).val()
27
+ trigger("selectedOutCurrency", selectedCurrencyCode)
28
+ $p(".in_currency").on 'change', ->
29
+ selectedCurrencyCode = $(this).val()
30
+ trigger("selectedInCurrency", selectedCurrencyCode)
31
+
32
+ bind: (event, handler) ->
33
+ eventHandlers[event] = handler
34
+
35
+ render: (message) ->
36
+ console.log('rendering...', message)
37
+ renderSection(section,data) for own section,data of message
38
+
39
+ get: (field) -> console.log( 'getting...', field )
40
+
41
+ show: -> console.log( 'showing...' )
42
+ hide: -> console.log( 'hiding...' )
@@ -0,0 +1 @@
1
+ # Define your custom styles for all platforms here.
@@ -0,0 +1,21 @@
1
+ tw ?= {}
2
+
3
+ tw.batSignal = () ->
4
+ _batSignal = () ->
5
+ if(!_iframe)
6
+ _iframe = document.createElement('iframe')
7
+ _iframe.setAttribute("id", "callback_iframe")
8
+ _iframe.setAttribute("style", "display:none;")
9
+ _iframe.setAttribute("height","0px")
10
+ _iframe.setAttribute("width","0px")
11
+ _iframe.setAttribute("frameborder","0")
12
+ document.documentElement.appendChild(_iframe)
13
+ return _iframe
14
+
15
+ tw.batSignalFor = (event) ->
16
+ (args...) ->
17
+ argStr = _.chain(args)
18
+ .filter((v) -> v?)
19
+ .reduce(((m, v) -> m + "&" + v), "")
20
+ .value()
21
+ window.batSignal().setAttribute('src', 'js-call:' + event + argStr)