Permalink
Browse files

AMD Conversion

"Trivial" JavaScript / CoffeeScript changes
--------------------------------------------------

For the most part, all javascript was simply
wrapped in `require` or `define`. The dependencies
were found with a script that matched regexes in
the files, it errs on the side of listing too many
dependencies, so its worth double checking each
file's dependencies (over time, anyway).

i18n API changes
--------------------------------------------------

No longer have to do I18n.scoped calls, just
list i18n as a dependency with the scope and it's
imported already scoped

  require ['i18n!some_scope'], (I18n) ->
    I18n.t 'im_scoped', 'I'm scoped!'

JS bundling now done with r.js, not Jammit
--------------------------------------------------

We don't use jammit to bundle JS anymore. Simply
list dependencies for your JS modules in the file
and RequireJS handles the rest.

To optimize the JavaScript, first make sure you
have node.js 0.4.12+ installed and then run:

  $ rake js:build

The app defaults to the optimized build in
production. You can use non-optimized in
production by putting ?debug_assets=true in the
url just like before.

You can also test the optimized JavaScript in
development with ?optimized_js=true.

Significant changes
--------------------------------------------------

These files have "real" changes to them (unlike
the JavaScript that is simply wrapped in require
and define).  Worth taking a really close look at:

- app/helpers/application_helper.rb
- app/views/layouts/application.html.erb
- config/assets.yml
- config/build.js
- lib/handlebars/handlebars.rb
- lib/i18n_extraction/js_extractor.rb
- lib/tasks/canvas.rake
- lib/tasks/i18n.rake
- lib/tasks/js.rake

Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7
Reviewed-on: https://gerrit.instructure.com/6986
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Florence <ryanf@instructure.com>
  • Loading branch information...
1 parent ccc1458 commit a1e31c8c9a55480a54a5ae6290756197adda8729 @ryanflorence ryanflorence committed Nov 10, 2011
Showing 524 changed files with 22,402 additions and 8,536 deletions.
View
@@ -55,3 +55,5 @@ public/doc/api/*
spec/javascripts/*Spec.js
spec/javascripts/*/*Spec.js
spec/javascripts/helpers/*
+public/optimized
+!node_modules
View
13 Gemfile
@@ -8,7 +8,6 @@ gem 'authlogic', '2.1.3'
gem "aws-s3-instructure", "~> 0.6.2.1319643167", :require => 'aws/s3'
gem 'bcrypt-ruby', '3.0.1'
gem 'builder', '2.1.2'
-gem 'closure-compiler','1.0.0'
gem 'compass', '0.11.5'
gem 'daemons', '1.1.0'
gem 'diff-lcs', '1.1.2', :require => 'diff/lcs'
@@ -91,19 +90,7 @@ group :redis do
end
-# The closure-compiler gem has an undocumented
-# gem dependency on windows with ruby < 1.9. I'm
-# working to get this fixed in the gem itself, but
-# in the mean time this needs to be here to make
-# things work on windows.
-WINDOWS = RUBY_PLATFORM.match(/(win|w)32$/)
ONE_NINE = RUBY_VERSION >= "1.9"
-if WINDOWS
- if !ONE_NINE
- gem 'win32-open3', '0.3.2'
- end
-end
-
if !ONE_NINE
gem 'fastercsv', '1.5.3'
end
@@ -1,18 +1,23 @@
-I18n.scoped 'AssignmentDetailsDialog', (I18n) ->
- class @AssignmentDetailsDialog
+define [
+ 'jquery'
+ 'jst/AssignmentDetailsDialog'
+ 'jquery.instructure_jquery_patches' # dialog
+], ($, assignmentDetailsDialogTemplate) ->
+
+ class AssignmentDetailsDialog
constructor: (@assignment, @gradebook) ->
scores = (student["assignment_#{@assignment.id}"].score for own idx, student of @gradebook.students when student["assignment_#{@assignment.id}"]?.score?)
locals =
assignment: @assignment
cnt: scores.length
max: Math.max scores...
min: Math.min scores...
- average: do (scores) ->
- total=0
+ average: do (scores) ->
+ total = 0
total += score for score in scores
Math.round(total / scores.length)
-
- tally = 0
+
+ tally = 0
width = 0
totalWidth = 100
$.extend locals,
@@ -26,6 +31,6 @@ I18n.scoped 'AssignmentDetailsDialog', (I18n) ->
noneRightWidth: width = totalWidth * ((@assignment.points_possible - locals.max) / @assignment.points_possible)
noneRightLeft: (tally += width) - width
- $(Template 'AssignmentDetailsDialog', locals).dialog
+ $(assignmentDetailsDialogTemplate(locals)).dialog
width: 375
- close: -> $(this).remove()
+ close: -> $(this).remove()
@@ -1,5 +1,14 @@
-I18n.scoped 'AssignmentMuter', (I18n) ->
- class @AssignmentMuter
+define [
+ 'i18n!assignment_muter'
+ 'jquery'
+ 'jst/mute_dialog'
+ 'jquery.ajaxJSON'
+ 'jquery.disableWhileLoading'
+ 'jquery.instructure_jquery_patches' # dialog
+ 'vendor/jquery.ba-tinypubsub'
+], (I18n, $, mute_dialog_template) ->
+
+ class AssignmentMuter
constructor: (@$link, @assignment, @url) ->
@$link = $(@$link)
@updateLink()
@@ -11,7 +20,7 @@ I18n.scoped 'AssignmentMuter', (I18n) ->
@$link.text(if @assignment.muted then I18n.t('unmute_assignment', 'Unmute Assignment') else I18n.t('mute_assignment', 'Mute Assignment'))
showDialog: =>
- @$dialog = $(Template('mute_dialog')).dialog
+ @$dialog = $(mute_dialog_template()).dialog
buttons: [{
text: I18n.t('mute_assignment', 'Mute Assignment')
'data-text-while-loading': I18n.t('muting_assignment', 'Muting Assignment...')
@@ -1,13 +1,24 @@
-I18n.scoped 'AssignmentDetailsDialog', (I18n) ->
- class @SubmissionDetailsDialog
+define [
+ 'jquery'
+ 'jst/SubmissionDetailsDialog'
+ 'jst/_submission_detail' # a partial needed by the SubmissionDetailsDialog template
+ 'jquery.ajaxJSON'
+ 'jquery.disableWhileLoading'
+ 'jquery.instructure_forms'
+ 'jquery.instructure_jquery_patches'
+ 'jquery.instructure_misc_plugins'
+ 'vendor/jquery.scrollTo'
+], ($, submissionDetailsDialog) ->
+
+ class SubmissionDetailsDialog
constructor: (@assignment, @student, @options) ->
@url = @options.change_grade_url.replace(":assignment", @assignment.id).replace(":submission", @student.id)
@submission = $.extend {}, @student["assignment_#{@assignment.id}"],
assignment: @assignment
speedGraderUrl: "#{@options.context_url}/gradebook/speed_grader?assignment_id=#{@assignment.id}#%7B%22student_id%22%3A#{@student.id}%7D"
loading: true
@dialog = $('<div class="use-css-transitions-for-show-hide" style="padding:0;"/>')
- @dialog.html(Template('SubmissionDetailsDialog', @submission))
+ @dialog.html(submissionDetailsDialog(@submission))
.dialog
title: @student.name
width: 600
@@ -49,11 +60,12 @@ I18n.scoped 'AssignmentDetailsDialog', (I18n) ->
if turnitinDataForThisAttachment = submission.turnitin_data?["attachment_#{attachment.id}"]
attachment.turnitinUrl = "#{@options.context_url}/assignments/#{@assignment.id}/submissions/#{@student.id}/turnitin/attachment_#{attachment.id}"
attachment.turnitin_data = turnitinDataForThisAttachment
- @dialog.html(Template('SubmissionDetailsDialog', @submission))
+ @dialog.html(submissionDetailsDialog(@submission))
@dialog.find('select').trigger('change')
@scrollCommentsToBottom()
@cachedDialogs: {}
@open: (assignment, student, options) ->
(SubmissionDetailsDialog.cachedDialogs["#{assignment.id}-#{student.id}"] ||= new SubmissionDetailsDialog(assignment, student, options)).open()
+
@@ -1,13 +1,11 @@
-define 'compiled/Template',
-# ['compiled/handlebars_helpers'],
-->
+define ['compiled/handlebars_helpers', 'jquery'], (Handlebars, jQuery) ->
# A client-side templating wrapper. Templates are compiled with the rake task
# `$ rake jst:compile` or automatically using the guard gem `$ guard`.
# Don't call the templating object directly (like Handlebars), use this class.
# export to window until we convert new stuff to modules
- class @Template
+ class Template
# If called w/o `new`, it will return the HTML string immediately.
# i.e. `Template(test, {foo: 'bar'})` => '<div>bar</div>'
@@ -0,0 +1 @@
+require ['account_settings', 'external_tools']
@@ -0,0 +1 @@
+require ['account_statistics']
@@ -0,0 +1,2 @@
+require ['alerts']
+
@@ -0,0 +1,2 @@
+require ['aligned_outcomes']
+
@@ -0,0 +1,2 @@
+require ['compiled/AssignmentMuter']
+
@@ -0,0 +1,2 @@
+require ['assignments']
+
@@ -0,0 +1,2 @@
+require ['datagrid', 'attendance']
+
@@ -0,0 +1,5 @@
+require [
+ 'calendar'
+ 'calendar_move'
+ 'content_locks'
+]
@@ -0,0 +1,16 @@
+# this is responsible for gluing all the calendar parts together into a complete page
+# the only thing on the erb page should be `calendarApp.init(<contexts>, <manageContexts>);`
+require [
+ 'jquery',
+ 'compiled/calendar/Calendar'
+ 'compiled/calendar/MiniCalendar'
+ 'compiled/calendar/sidebar'
+ 'compiled/calendar/EventDataSource'
+ 'compiled/calendar/UndatedEventsList'
+ 'compiled/bundles/jquery_ui_menu'
+], ($, Calendar, MiniCalendar, drawSidebar, EventDataSource, UndatedEventsList) ->
+ @eventDataSource = new EventDataSource(ENV.CALENDAR.CONTEXTS)
+ @calendar = new Calendar("#calendar-app", ENV.CALENDAR.CONTEXTS, ENV.CALENDAR.MANAGE_CONTEXTS, @eventDataSource)
+ new MiniCalendar("#minical", @calendar)
+ new UndatedEventsList("#undated-events", @eventDataSource)
+ drawSidebar(ENV.CALENDAR.CONTEXTS, @eventDataSource)
@@ -0,0 +1,2 @@
+require ['calendar_event']
+
@@ -0,0 +1,2 @@
+require ['collaborations']
+
@@ -0,0 +1,37 @@
+require [
+ # true modules that we manage in this file
+ 'compiled/widget/courseList'
+ 'compiled/helpDialog'
+
+ # modules that do their own thing on every page that simply need to
+ # be required
+ 'translations/_core_en'
+ 'jquery.ajaxJSON'
+ 'vendor/firebugx'
+ 'jquery.google-analytics'
+ 'vendor/swfobject/swfobject'
+ 'reminders'
+ 'jquery.instructure_forms'
+ 'tinymce.editor_box'
+ 'instructure'
+ 'ajax_errors'
+ 'page_views'
+ 'compiled/license_help'
+
+ # stuff we simply want to load since it's used regularly across
+ # several modules
+ 'tinymce.editor_box'
+
+ # random modules required by the js_blocks, put them all in here
+ # so RequireJS doesn't try to load them before common is loaded
+ # in an optimized environment
+ 'jquery.fancyplaceholder'
+ 'jqueryui/autocomplete'
+ 'link_enrollment'
+ 'media_comments'
+ 'vendor/jquery.pageless'
+ 'vendor/jquery.scrollTo'
+], (courseList, helpDialog) ->
+ courseList.init()
+ helpDialog.initTriggers()
+
@@ -0,0 +1,2 @@
+require ['conferences']
+
@@ -0,0 +1,2 @@
+require ['content_exports']
+
@@ -0,0 +1,5 @@
+require [
+ 'compiled/util/processMigrationItemSelections'
+ 'content_imports'
+]
+
@@ -0,0 +1 @@
+require ['content_migration']
@@ -0,0 +1,2 @@
+require ['context_modules']
+
@@ -0,0 +1,5 @@
+require [
+ 'compiled/util/processItemSelections'
+ 'copy_course'
+]
+
@@ -0,0 +1,2 @@
+require ['course', 'context_modules']
+
@@ -0,0 +1,7 @@
+require [
+ 'vendor/jquery.cookie'
+ 'user_lists'
+ 'course_settings'
+ 'external_tools'
+ 'grading_standards'
+]
@@ -0,0 +1,2 @@
+require ['dashboard']
+
@@ -0,0 +1,2 @@
+require ['datagrid']
+
@@ -0,0 +1,2 @@
+require ['context_inbox']
+
@@ -0,0 +1 @@
+require ['edit_rubric']
@@ -0,0 +1,2 @@
+require ['eportfolio']
+
@@ -0,0 +1,2 @@
+require ['file_inline']
+
@@ -0,0 +1 @@
+require ['full_assignment', 'grading_standards']
@@ -0,0 +1,2 @@
+require ['full_files', 'uploadify']
+
@@ -0,0 +1 @@
+require ['grade_summary', 'compiled/grade_calculator']
@@ -0,0 +1,5 @@
+require [
+ 'compiled/gradebook2/Gradebook'
+], (Gradebook) ->
+ new Gradebook(GRADEBOOK_OPTIONS)
+
@@ -0,0 +1,2 @@
+require ['gradebook-history']
+
@@ -0,0 +1,2 @@
+require [ 'jquery', 'gradebook_uploads'], ($, GradebookUploader) ->
+ $(GradebookUploader.handleThingsNeedingToBeResolved)
@@ -0,0 +1,6 @@
+require [
+ 'gradebooks'
+ 'message_students'
+ 'compiled/grade_calculator'
+]
+
@@ -0,0 +1,2 @@
+require ['grading_standards']
+
@@ -0,0 +1 @@
+require ['vendor/graphael']
@@ -0,0 +1,2 @@
+require ['groups']
+
@@ -0,0 +1,7 @@
+require ['jquery', 'compiled/jobs'], ($, jobs) ->
+ # TODO: get this stuff off window, need to move the domready stuff out of
+ # jobs.coffee into here
+ window.jobs = new jobs.Jobs(ENV.JOBS.opts).init()
+ window.running = new jobs.Workers(ENV.JOBS.running_opts).init()
+ window.tags = new jobs.Tags(ENV.JOBS.tags_opts).init()
+
@@ -0,0 +1,2 @@
+require ['compiled/jquery.kylemenu']
+
@@ -0,0 +1,2 @@
+require ['vendor/json2']
+
@@ -0,0 +1,2 @@
+require ['learning_outcome']
+
@@ -0,0 +1,2 @@
+require ['learning_outcomes']
+
@@ -0,0 +1 @@
+require ['link_enrollment']
@@ -0,0 +1,2 @@
+require ['manage_avatars']
+
@@ -0,0 +1,2 @@
+require ['manage_groups']
+
@@ -0,0 +1,7 @@
+require [
+ 'compiled/messages'
+ 'compiled/slideshow'
+ 'compiled/conversations_intro'
+ 'vendor/jquery.elastic'
+ 'vendor/jquery.cookie'
+]
@@ -0,0 +1 @@
+require ['quiz_timing', 'moderate_quiz']
@@ -0,0 +1,2 @@
+require ['plugins']
+
@@ -0,0 +1,2 @@
+require ['prerequisites_lookup']
+
@@ -0,0 +1,5 @@
+require [
+ 'compiled/util/BackoffPoller'
+ 'profile'
+ 'user_sortable_name'
+]
@@ -0,0 +1,5 @@
+require [
+ 'jst/quiz/move_question'
+ 'question_bank'
+ 'find_outcome'
+]
@@ -0,0 +1,2 @@
+require ['question_banks']
+
@@ -0,0 +1,6 @@
+require [
+ 'quiz_show'
+ 'quiz_rubric'
+ 'message_students'
+]
+
Oops, something went wrong.

0 comments on commit a1e31c8

Please sign in to comment.