scorm_rte 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c3c6ac2ca40a1285cbe11dbe9031b0320bcc152
4
+ data.tar.gz: 2a94ad15b82c043fbe1489acfa6a0308cb719995
5
+ SHA512:
6
+ metadata.gz: 66a27c2ac503427fcd88678fc964c8d01148b116edcde6dc56bd14ac3c0ba105075d2c54e0c64bdad207d17701216c03cf393cbcabbade7b3c77d6aed0f11ca5
7
+ data.tar.gz: 879f70b186c1ec2672f608363ac727266065f74646cf14384b1f1ba82d342c7b02dad68f806bfd4892dd602d0b3b20545d02991b78a2e4c0bcc9a597c10e93aa
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 paresharma
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.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ScormRte'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,285 @@
1
+ function LMSAPI(){
2
+ this.cache = {};
3
+ this.SCOInstanceID = 123456789;
4
+
5
+ // 1.2
6
+ this.LMSInitialize=LMSInitialize;
7
+ this.LMSGetValue=LMSGetValue;
8
+ this.LMSSetValue=LMSSetValue;
9
+ this.LMSCommit=LMSCommit;
10
+ this.LMSFinish=LMSFinish;
11
+ this.LMSGetLastError=LMSGetLastError;
12
+ this.LMSGetDiagnostic=LMSGetDiagnostic;
13
+ this.LMSGetErrorString=LMSGetErrorString;
14
+
15
+ // 2004
16
+ this.Initialize=LMSInitialize;
17
+ this.GetValue=LMSGetValue;
18
+ this.SetValue=LMSSetValue;
19
+ this.Commit=LMSCommit;
20
+ this.Treminate=LMSFinish;
21
+ this.GetLastError=LMSGetLastError;
22
+ this.GetDiagnostic=LMSGetDiagnostic;
23
+ this.GetErrorString=LMSGetErrorString;
24
+
25
+ // ------------------------------------------
26
+ // Status Flags
27
+ // ------------------------------------------
28
+ var flagFinished = false;
29
+
30
+ // ------------------------------------------
31
+ // SCO Data Cache - Initialization
32
+ // ------------------------------------------
33
+
34
+ // ------------------------------------------
35
+ // SCORM RTE Functions - Initialization
36
+ // ------------------------------------------
37
+ function LMSInitialize(dummyString) {
38
+ console.log('***');
39
+ console.log('initialized');
40
+ console.log(this.cache);
41
+
42
+ var url = 'http://localhost:3000/scorm_rte/stores/fetch?sco_instance_id='+this.SCOInstanceID;
43
+ var tempCache = {};
44
+
45
+ $.ajax({
46
+ url: url,
47
+ dataType: 'json',
48
+ async: false
49
+ }).done(function( data ) {
50
+ tempCache = data;
51
+ });
52
+
53
+ // this.cache = JSON.parse(localStorage.getItem('k')) || {}
54
+ this.cache = tempCache;
55
+ console.log(this.cache);
56
+ console.log('***');
57
+ return "true";
58
+ }
59
+
60
+ // ------------------------------------------
61
+ // SCORM RTE Functions - Getting and Setting Values
62
+ // ------------------------------------------
63
+ function LMSGetValue(varname) {
64
+ //alert(this.cache[varname]);
65
+ var v = this.cache[varname];
66
+ if(v == undefined){
67
+ v = ""
68
+ }
69
+ return v
70
+ }
71
+
72
+ function LMSSetValue(varname,varvalue) {
73
+ this.cache[varname] = varvalue;
74
+ return "true";
75
+ }
76
+
77
+ // ------------------------------------------
78
+ // SCORM RTE Functions - Saving the Cache to the Database
79
+ // ------------------------------------------
80
+ function LMSCommit(dummyString) {
81
+ // code to prevent caching
82
+ var d = new Date();
83
+
84
+
85
+ // create a POST-formatted list of cached data elements
86
+ // include only SCO-writeable data elements
87
+ var params = 'scorm_rte_store[sco_instance_id]='+this.SCOInstanceID+'&code='+d.getTime();
88
+ params += "&scorm_rte_store[data][cmi.core.lesson_location]="+urlencode(this.cache['cmi.core.lesson_location']);
89
+ params += "&scorm_rte_store[data][cmi.core.lesson_status]="+urlencode(this.cache['cmi.core.lesson_status']);
90
+ params += "&scorm_rte_store[data][cmi.core.exit]="+urlencode(this.cache['cmi.core.exit']);
91
+ params += "&scorm_rte_store[data][cmi.core.session_time]="+urlencode(this.cache['cmi.core.session_time']);
92
+ params += "&scorm_rte_store[data][cmi.core.score.raw]="+urlencode(this.cache['cmi.core.score.raw']);
93
+ params += "&scorm_rte_store[data][cmi.suspend_data]="+urlencode(this.cache['cmi.suspend_data']);
94
+
95
+ // submit to the server for processing
96
+ var url = "http://localhost:3000/scorm_rte/stores"
97
+ $.ajax({
98
+ type: "POST",
99
+ headers: {
100
+ 'Content-type' : 'application/x-www-form-urlencoded',
101
+ 'Content-length' : params.length,
102
+ 'Connection' : 'close'
103
+ },
104
+ url: url,
105
+ data: params
106
+ });
107
+
108
+ // process returned data - error condition
109
+ // if (req.status != 200) {
110
+ // alert('Problem with AJAX Request in LMSCommit()');
111
+ // return "false";
112
+ // }
113
+
114
+ // process returned data - OK
115
+ // else {
116
+ // return "true";
117
+ // }
118
+ return "true";
119
+ }
120
+
121
+ // ------------------------------------------
122
+ // SCORM RTE Functions - Closing The Session
123
+ // ------------------------------------------
124
+ function LMSFinish(dummyString) {
125
+
126
+ // already finished - prevent repeat call
127
+ if (flagFinished) {
128
+ return "true";
129
+ }
130
+
131
+ // commit cached values to the database
132
+ console.log('!! finish')
133
+
134
+ // console.log('***')
135
+ // console.log(localStorage.getItem('k'))
136
+ // localStorage.setItem('k', JSON.stringify(this.cache))
137
+ console.log(this.cache)
138
+ // console.log(JSON.parse(localStorage.getItem('k')))
139
+ // console.log('###')
140
+
141
+ LMSCommit('');
142
+ console.log('!! finish !!')
143
+ /*
144
+ // create request object
145
+ var req = createRequest();
146
+
147
+ // code to prevent caching
148
+ var d = new Date();
149
+
150
+ // set up request parameters - uses GET method
151
+ req.open('GET','finish.php?SCOInstanceID=<?php print $SCOInstanceID; ?>&code='+d.getTime(),false);
152
+
153
+ // submit to the server for processing
154
+ req.send(null);
155
+
156
+ // process returned data - error condition
157
+ if (req.status != 200) {
158
+ alert('Problem with AJAX Request in LMSFinish()');
159
+ return "";
160
+ }
161
+
162
+ */
163
+ // set finish flag
164
+ flagFinished = true;
165
+ // return to calling program
166
+ return "true";
167
+
168
+ }
169
+
170
+ // ------------------------------------------
171
+ // SCORM RTE Functions - Error Handling
172
+ // ------------------------------------------
173
+ function LMSGetLastError() {
174
+ return 0;
175
+ }
176
+
177
+ function LMSGetDiagnostic(errorCode) {
178
+ return "diagnostic string";
179
+ }
180
+
181
+ function LMSGetErrorString(errorCode) {
182
+ return "error string";
183
+ }
184
+
185
+ // ------------------------------------------
186
+ // URL Encoding
187
+ // ------------------------------------------
188
+ function urlencode( str ) {
189
+ //
190
+ // Ref: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/
191
+ //
192
+ // http://kevin.vanzonneveld.net
193
+ // + original by: Philip Peterson
194
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
195
+ // + input by: AJ
196
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
197
+ // + improved by: Brett Zamir (http://brettz9.blogspot.com)
198
+ // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
199
+ // + input by: travc
200
+ // + input by: Brett Zamir (http://brettz9.blogspot.com)
201
+ // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
202
+ // + improved by: Lars Fischer
203
+ // % note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
204
+ // * example 1: urlencode('Kevin van Zonneveld!');
205
+ // * returns 1: 'Kevin+van+Zonneveld%21'
206
+ // * example 2: urlencode('http://kevin.vanzonneveld.net/');
207
+ // * returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
208
+ // * example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
209
+ // * returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
210
+
211
+ var histogram = {}, unicodeStr='', hexEscStr='';
212
+ var ret = (str+'').toString();
213
+
214
+ var replacer = function(search, replace, str) {
215
+ var tmp_arr = [];
216
+ tmp_arr = str.split(search);
217
+ return tmp_arr.join(replace);
218
+ };
219
+
220
+ // The histogram is identical to the one in urldecode.
221
+ histogram["'"] = '%27';
222
+ histogram['('] = '%28';
223
+ histogram[')'] = '%29';
224
+ histogram['*'] = '%2A';
225
+ histogram['~'] = '%7E';
226
+ histogram['!'] = '%21';
227
+ histogram['%20'] = '+';
228
+ histogram['\u00DC'] = '%DC';
229
+ histogram['\u00FC'] = '%FC';
230
+ histogram['\u00C4'] = '%D4';
231
+ histogram['\u00E4'] = '%E4';
232
+ histogram['\u00D6'] = '%D6';
233
+ histogram['\u00F6'] = '%F6';
234
+ histogram['\u00DF'] = '%DF';
235
+ histogram['\u20AC'] = '%80';
236
+ histogram['\u0081'] = '%81';
237
+ histogram['\u201A'] = '%82';
238
+ histogram['\u0192'] = '%83';
239
+ histogram['\u201E'] = '%84';
240
+ histogram['\u2026'] = '%85';
241
+ histogram['\u2020'] = '%86';
242
+ histogram['\u2021'] = '%87';
243
+ histogram['\u02C6'] = '%88';
244
+ histogram['\u2030'] = '%89';
245
+ histogram['\u0160'] = '%8A';
246
+ histogram['\u2039'] = '%8B';
247
+ histogram['\u0152'] = '%8C';
248
+ histogram['\u008D'] = '%8D';
249
+ histogram['\u017D'] = '%8E';
250
+ histogram['\u008F'] = '%8F';
251
+ histogram['\u0090'] = '%90';
252
+ histogram['\u2018'] = '%91';
253
+ histogram['\u2019'] = '%92';
254
+ histogram['\u201C'] = '%93';
255
+ histogram['\u201D'] = '%94';
256
+ histogram['\u2022'] = '%95';
257
+ histogram['\u2013'] = '%96';
258
+ histogram['\u2014'] = '%97';
259
+ histogram['\u02DC'] = '%98';
260
+ histogram['\u2122'] = '%99';
261
+ histogram['\u0161'] = '%9A';
262
+ histogram['\u203A'] = '%9B';
263
+ histogram['\u0153'] = '%9C';
264
+ histogram['\u009D'] = '%9D';
265
+ histogram['\u017E'] = '%9E';
266
+ histogram['\u0178'] = '%9F';
267
+
268
+ // Begin with encodeURIComponent, which most resembles PHP's encoding functions
269
+ ret = encodeURIComponent(ret);
270
+
271
+ for (unicodeStr in histogram) {
272
+ hexEscStr = histogram[unicodeStr];
273
+ ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
274
+ }
275
+
276
+ // Uppercase for full PHP compatibility
277
+ return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
278
+ return "%"+m2.toUpperCase();
279
+ });
280
+ }
281
+
282
+ }
283
+
284
+ window.API = new LMSAPI();
285
+ window.API_1484_11 = new LMSAPI();
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ScormRte
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module ScormRte
2
+ class StoresController < ApplicationController
3
+ def fetch
4
+ store = Store.find_by(sco_instance_id: params[:sco_instance_id])
5
+ render json: (store.data || {}.to_json)
6
+ end
7
+
8
+ def create
9
+ store = Store.find_or_initialize_by(
10
+ sco_instance_id: params[:scorm_rte_store][:sco_instance_id]
11
+ )
12
+
13
+ store.data = params[:scorm_rte_store][:data].to_json
14
+ store.save
15
+
16
+ render nothing: true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module ScormRte
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ScormRte
2
+ class Store < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>ScormRte</title>
5
+ <%= stylesheet_link_tag "scorm_rte/application", media: "all" %>
6
+ <%= javascript_include_tag "scorm_rte/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ ScormRte::Engine.routes.draw do
2
+ resource :stores, only: :create do
3
+ get :fetch
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class CreateScormRteStores < ActiveRecord::Migration
2
+ def change
3
+ create_table :scorm_rte_stores do |t|
4
+ t.string :sco_instance_id
5
+ t.text :data
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
data/lib/scorm_rte.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'scorm_rte/engine'
2
+
3
+ module ScormRte
4
+ end
@@ -0,0 +1,5 @@
1
+ module ScormRte
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ScormRte
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ScormRte
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :scorm_rte do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scorm_rte
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - paresharma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This is an attempt to a mountable rails engine for SCORM RTE.
42
+ email:
43
+ - paresharma@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - Rakefile
50
+ - app/assets/javascripts/scorm_rte/application.js
51
+ - app/assets/javascripts/scorm_rte/rte.js
52
+ - app/assets/stylesheets/scorm_rte/application.css
53
+ - app/controllers/scorm_rte/application_controller.rb
54
+ - app/controllers/scorm_rte/stores_controller.rb
55
+ - app/helpers/scorm_rte/application_helper.rb
56
+ - app/models/scorm_rte/store.rb
57
+ - app/views/layouts/scorm_rte/application.html.erb
58
+ - config/routes.rb
59
+ - db/migrate/20150321231502_create_scorm_rte_stores.rb
60
+ - lib/scorm_rte.rb
61
+ - lib/scorm_rte/engine.rb
62
+ - lib/scorm_rte/version.rb
63
+ - lib/tasks/scorm_rte_tasks.rake
64
+ homepage: https://github.com/pukei/scorm_rte
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.5
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Mountable Runtime Environment for SCORM RTE.
88
+ test_files: []