padrino-angularjs 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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Configuration for jstd scenario adapter
3
+ */
4
+ var jstdScenarioAdapter = {
5
+ relativeUrlPrefix: '/build/docs/'
6
+ };
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @license AngularJS v1.0.4
3
+ * (c) 2010-2012 Google, Inc. http://angularjs.org
4
+ * License: MIT
5
+ */
6
+ (function(window) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * JSTestDriver adapter for angular scenario tests
11
+ *
12
+ * Example of jsTestDriver.conf for running scenario tests with JSTD:
13
+ <pre>
14
+ server: http://localhost:9877
15
+
16
+ load:
17
+ - lib/angular-scenario.js
18
+ - lib/jstd-scenario-adapter-config.js
19
+ - lib/jstd-scenario-adapter.js
20
+ # your test files go here #
21
+
22
+ proxy:
23
+ - {matcher: "/your-prefix/*", server: "http://localhost:8000/"}
24
+ </pre>
25
+ *
26
+ * For more information on how to configure jstd proxy, see {@link http://code.google.com/p/js-test-driver/wiki/Proxy}
27
+ * Note the order of files - it's important !
28
+ *
29
+ * Example of jstd-scenario-adapter-config.js
30
+ <pre>
31
+ var jstdScenarioAdapter = {
32
+ relativeUrlPrefix: '/your-prefix/'
33
+ };
34
+ </pre>
35
+ *
36
+ * Whenever you use <code>browser().navigateTo('relativeUrl')</code> in your scenario test, the relativeUrlPrefix will be prepended.
37
+ * You have to configure this to work together with JSTD proxy.
38
+ *
39
+ * Let's assume you are using the above configuration (jsTestDriver.conf and jstd-scenario-adapter-config.js):
40
+ * Now, when you call <code>browser().navigateTo('index.html')</code> in your scenario test, the browser will open /your-prefix/index.html.
41
+ * That matches the proxy, so JSTD will proxy this request to http://localhost:8000/index.html.
42
+ */
43
+
44
+ /**
45
+ * Custom type of test case
46
+ *
47
+ * @const
48
+ * @see jstestdriver.TestCaseInfo
49
+ */
50
+ var SCENARIO_TYPE = 'scenario';
51
+
52
+ /**
53
+ * Plugin for JSTestDriver
54
+ * Connection point between scenario's jstd output and jstestdriver.
55
+ *
56
+ * @see jstestdriver.PluginRegistrar
57
+ */
58
+ function JstdPlugin() {
59
+ var nop = function() {};
60
+
61
+ this.reportResult = nop;
62
+ this.reportEnd = nop;
63
+ this.runScenario = nop;
64
+
65
+ this.name = 'Angular Scenario Adapter';
66
+
67
+ /**
68
+ * Called for each JSTD TestCase
69
+ *
70
+ * Handles only SCENARIO_TYPE test cases. There should be only one fake TestCase.
71
+ * Runs all scenario tests (under one fake TestCase) and report all results to JSTD.
72
+ *
73
+ * @param {jstestdriver.TestRunConfiguration} configuration
74
+ * @param {Function} onTestDone
75
+ * @param {Function} onAllTestsComplete
76
+ * @returns {boolean} True if this type of test is handled by this plugin, false otherwise
77
+ */
78
+ this.runTestConfiguration = function(configuration, onTestDone, onAllTestsComplete) {
79
+ if (configuration.getTestCaseInfo().getType() != SCENARIO_TYPE) return false;
80
+
81
+ this.reportResult = onTestDone;
82
+ this.reportEnd = onAllTestsComplete;
83
+ this.runScenario();
84
+
85
+ return true;
86
+ };
87
+
88
+ this.getTestRunsConfigurationFor = function(testCaseInfos, expressions, testRunsConfiguration) {
89
+ testRunsConfiguration.push(
90
+ new jstestdriver.TestRunConfiguration(
91
+ new jstestdriver.TestCaseInfo(
92
+ 'Angular Scenario Tests', function() {}, SCENARIO_TYPE), []));
93
+
94
+ return true;
95
+ };
96
+ }
97
+
98
+ /**
99
+ * Singleton instance of the plugin
100
+ * Accessed using closure by:
101
+ * - jstd output (reports to this plugin)
102
+ * - initScenarioAdapter (register the plugin to jstd)
103
+ */
104
+ var plugin = new JstdPlugin();
105
+
106
+ /**
107
+ * Initialise scenario jstd-adapter
108
+ * (only if jstestdriver is defined)
109
+ *
110
+ * @param {Object} jstestdriver Undefined when run from browser (without jstd)
111
+ * @param {Function} initScenarioAndRun Function that inits scenario and runs all the tests
112
+ * @param {Object=} config Configuration object, supported properties:
113
+ * - relativeUrlPrefix: prefix for all relative links when navigateTo()
114
+ */
115
+ function initScenarioAdapter(jstestdriver, initScenarioAndRun, config) {
116
+ if (jstestdriver) {
117
+ // create and register ScenarioPlugin
118
+ jstestdriver.pluginRegistrar.register(plugin);
119
+ plugin.runScenario = initScenarioAndRun;
120
+
121
+ /**
122
+ * HACK (angular.scenario.Application.navigateTo)
123
+ *
124
+ * We need to navigate to relative urls when running from browser (without JSTD),
125
+ * because we want to allow running scenario tests without creating its own virtual host.
126
+ * For example: http://angular.local/build/docs/docs-scenario.html
127
+ *
128
+ * On the other hand, when running with JSTD, we need to navigate to absolute urls,
129
+ * because of JSTD proxy. (proxy, because of same domain policy)
130
+ *
131
+ * So this hack is applied only if running with JSTD and change all relative urls to absolute.
132
+ */
133
+ var appProto = angular.scenario.Application.prototype,
134
+ navigateTo = appProto.navigateTo,
135
+ relativeUrlPrefix = config && config.relativeUrlPrefix || '/';
136
+
137
+ appProto.navigateTo = function(url, loadFn, errorFn) {
138
+ if (url.charAt(0) != '/' && url.charAt(0) != '#' &&
139
+ url != 'about:blank' && !url.match(/^https?/)) {
140
+ url = relativeUrlPrefix + url;
141
+ }
142
+
143
+ return navigateTo.call(this, url, loadFn, errorFn);
144
+ };
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Builds proper TestResult object from given model spec
150
+ *
151
+ * TODO(vojta) report error details
152
+ *
153
+ * @param {angular.scenario.ObjectModel.Spec} spec
154
+ * @returns {jstestdriver.TestResult}
155
+ */
156
+ function createTestResultFromSpec(spec) {
157
+ var map = {
158
+ success: 'PASSED',
159
+ error: 'ERROR',
160
+ failure: 'FAILED'
161
+ };
162
+
163
+ return new jstestdriver.TestResult(
164
+ spec.fullDefinitionName,
165
+ spec.name,
166
+ jstestdriver.TestResult.RESULT[map[spec.status]],
167
+ spec.error || '',
168
+ spec.line || '',
169
+ spec.duration);
170
+ }
171
+
172
+ /**
173
+ * Generates JSTD output (jstestdriver.TestResult)
174
+ */
175
+ angular.scenario.output('jstd', function(context, runner, model) {
176
+ model.on('SpecEnd', function(spec) {
177
+ plugin.reportResult(createTestResultFromSpec(spec));
178
+ });
179
+
180
+ model.on('RunnerEnd', function() {
181
+ plugin.reportEnd();
182
+ });
183
+ });
184
+ initScenarioAdapter(window.jstestdriver, angular.scenario.setUpAndRun, window.jstdScenarioAdapter);
185
+ })(window);
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: padrino-angularjs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Takeshi Yabe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: This gem to use AngularJS to a Padrino apps
31
+ email:
32
+ - tyabe@nilidea.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/padrino/angularjs.rb
44
+ - lib/padrino/angularjs/generators/install.rb
45
+ - lib/padrino/angularjs/generators/templates/application.js.tt
46
+ - lib/padrino/angularjs/version.rb
47
+ - padrino-angularjs.gemspec
48
+ - spec/padrino/angularjs_spec.rb
49
+ - spec/spec_helper.rb
50
+ - vendor/assets/javascripts/angular-bootstrap-prettify.js
51
+ - vendor/assets/javascripts/angular-bootstrap.js
52
+ - vendor/assets/javascripts/angular-cookies.js
53
+ - vendor/assets/javascripts/angular-loader.js
54
+ - vendor/assets/javascripts/angular-mocks.js
55
+ - vendor/assets/javascripts/angular-resource.js
56
+ - vendor/assets/javascripts/angular-sanitize.js
57
+ - vendor/assets/javascripts/angular-scenario.js
58
+ - vendor/assets/javascripts/angular.js
59
+ - vendor/assets/javascripts/jstd-scenario-adapter-config.js
60
+ - vendor/assets/javascripts/jstd-scenario-adapter.js
61
+ homepage: https://github.com/tyabe/padrino-angularjs#readme
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: AngularJS on Padrino
86
+ test_files:
87
+ - spec/padrino/angularjs_spec.rb
88
+ - spec/spec_helper.rb