diff --git a/common/static/coffee/spec/discussion/discussion_spec_helper.coffee b/common/static/coffee/spec/discussion/discussion_spec_helper.coffee index c969f7edd0..0fee756658 100644 --- a/common/static/coffee/spec/discussion/discussion_spec_helper.coffee +++ b/common/static/coffee/spec/discussion/discussion_spec_helper.coffee @@ -44,6 +44,7 @@ class @DiscussionSpecHelper 'thread-list-item', 'discussion-home', 'search-alert', 'new-post', 'thread-type', 'new-post-menu-entry', 'new-post-menu-category', 'topic', 'post-user-display', + 'inline-discussion', 'pagination', 'user-profile', 'profile-thread' ] templateNamesNoTrailingTemplate = [ 'forum-action-endorse', 'forum-action-answer', 'forum-action-follow', diff --git a/common/static/coffee/spec/discussion/view/discussion_thread_profile_view_spec.coffee b/common/static/coffee/spec/discussion/view/discussion_thread_profile_view_spec.coffee index 4806004e23..eddd792e23 100644 --- a/common/static/coffee/spec/discussion/view/discussion_thread_profile_view_spec.coffee +++ b/common/static/coffee/spec/discussion/view/discussion_thread_profile_view_spec.coffee @@ -2,30 +2,22 @@ describe "DiscussionThreadProfileView", -> beforeEach -> - - setFixtures """ -
- - """ + DiscussionSpecHelper.setUpGlobals() + DiscussionSpecHelper.setUnderscoreFixtures() @threadData = { id: "1", body: "dummy body", discussion: new Discussion() abuse_flaggers: [], commentable_id: 'dummy_discussion', - votes: {up_count: "42"} + votes: {up_count: "42"}, + created_at: "2014-09-09T20:11:08Z" } @imageTag = '' window.MathJax = { Hub: { Queue: -> } } makeView = (thread) -> - view = new DiscussionThreadProfileView(el: $("article#thread_#{thread.id}"), model: thread) + view = new DiscussionThreadProfileView(model: thread) spyConvertMath(view) return view diff --git a/common/static/coffee/spec/discussion/view/discussion_user_profile_view_spec.coffee b/common/static/coffee/spec/discussion/view/discussion_user_profile_view_spec.coffee index af5395f4ca..c3bb52fe41 100644 --- a/common/static/coffee/spec/discussion/view/discussion_user_profile_view_spec.coffee +++ b/common/static/coffee/spec/discussion/view/discussion_user_profile_view_spec.coffee @@ -1,57 +1,14 @@ describe "DiscussionUserProfileView", -> beforeEach -> DiscussionSpecHelper.setUpGlobals() - setFixtures( - """ - - - -
- """ - ) + DiscussionSpecHelper.setUnderscoreFixtures() spyOn(DiscussionThreadProfileView.prototype, "render") + makeThreads = (numThreads) -> + _.map(_.range(numThreads), (i) -> {id: i.toString(), body: "dummy body"}) + makeView = (threads, page, numPages) -> - return new DiscussionUserProfileView( - el: $(".user-profile-fixture") + new DiscussionUserProfileView( collection: threads page: page numPages: numPages @@ -59,7 +16,7 @@ describe "DiscussionUserProfileView", -> describe "thread rendering should be correct", -> checkRender = (numThreads) -> - threads = _.map(_.range(numThreads), (i) -> {id: i.toString(), body: "dummy body"}) + threads = makeThreads(numThreads) view = makeView(threads, 1, 1) expect(view.$(".discussion").children().length).toEqual(numThreads) _.each(threads, (thread) -> expect(view.$("#thread_#{thread.id}").length).toEqual(1)) @@ -80,28 +37,18 @@ describe "DiscussionUserProfileView", -> checkRender = (params) -> view = makeView([], params.page, params.numPages) - paramsQuery = view.$(".pagination-params") - expect(paramsQuery.length).toEqual(1) - _.each( - ["page", "leftdots", "rightdots"], - (param) -> - expect(paramsQuery.data(param)).toEqual(params[param]) - ) - _.each( - ["previous", "first", "last", "next"], - (param) -> - expected = params[param] - expect(paramsQuery.find("." + param).data()).toEqual( - if expected then pageInfo(expected) else null - ) - ) - _.each( - ["lowPages", "highPages"] - (param) -> - expect(paramsQuery.find("." + param).map(-> $(this).data()).get()).toEqual( - _.map(params[param], pageInfo) - ) - ) + paginator = view.$(".discussion-paginator") + expect(paginator.find(".current-page").text()).toEqual(params["page"].toString()) + expect(paginator.find(".first-page").length).toBe(if params["first"] then 1 else 0); + expect(paginator.find(".previous-page").length).toBe(if params["previous"] then 1 else 0); + expect(paginator.find(".previous-ellipses").length).toBe(if params["leftdots"] then 1 else 0); + expect(paginator.find(".next-page").length).toBe(if params["next"] then 1 else 0); + expect(paginator.find(".next-ellipses").length).toBe(if params["rightdots"] then 1 else 0); + expect(paginator.find(".last-page").length).toBe(if params["last"] then 1 else 0); + + get_page_number = (element) => parseInt($(element).text()) + expect(_.map(paginator.find(".lower-page a"), get_page_number)).toEqual(params["lowPages"]) + expect(_.map(paginator.find(".higher-page a"), get_page_number)).toEqual(params["highPages"]) it "for one page", -> checkRender( @@ -245,7 +192,7 @@ describe "DiscussionUserProfileView", -> describe "pagination interaction", -> beforeEach -> - @view = makeView([], 1, 1) + @view = makeView(makeThreads(3), 1, 2) spyOn($, "ajax") it "causes updated rendering", -> @@ -259,9 +206,8 @@ describe "DiscussionUserProfileView", -> {always: ->} ) @view.$(".pagination a").first().click() - expect(@view.$("#thread_on_page_42").length).toEqual(1) - expect(@view.$(".pagination-params").data("page")).toEqual(42) - expect(@view.$(".pagination-params .last").data("number")).toEqual(99) + expect(@view.$(".current-page").text()).toEqual("42") + expect(@view.$(".last-page").text()).toEqual("99") it "handles AJAX errors", -> spyOn(DiscussionUtil, "discussionAlert") diff --git a/common/static/coffee/src/discussion/discussion_module_view.coffee b/common/static/coffee/src/discussion/discussion_module_view.coffee index 4cc0818cdc..9733e6658f 100644 --- a/common/static/coffee/src/discussion/discussion_module_view.coffee +++ b/common/static/coffee/src/discussion/discussion_module_view.coffee @@ -9,7 +9,6 @@ if Backbone? (event) -> DiscussionUtil.activateOnSpace(event, @toggleNewPost) "click .discussion-paginator a": "navigateToPage" - paginationTemplate: -> DiscussionUtil.getTemplate("_pagination") page_re: /\?discussion_page=(\d+)/ initialize: -> @toggleDiscussionBtn = @$(".discussion-show") @@ -91,7 +90,10 @@ if Backbone? @discussion = new Discussion() @discussion.reset(response.discussion_data, {silent: false}) - $discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data, 'discussionId': discussionId}) + $discussion = _.template($("#inline-discussion-template").html())( + 'threads': response.discussion_data, + 'discussionId': discussionId + ) if @$('section.discussion').length @$('section.discussion').replaceWith($discussion) else @@ -149,8 +151,8 @@ if Backbone? pageUrl = (number) -> "?discussion_page=#{number}" params = DiscussionUtil.getPaginationParams(@page, numPages, pageUrl) - thing = Mustache.render @paginationTemplate(), params - @$('section.pagination').html(thing) + pagination = _.template($("#pagination-template").html())(params) + @$('section.pagination').html(pagination) navigateToPage: (event) => event.preventDefault() diff --git a/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee index 2d248f49c7..7eb42aa321 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee @@ -1,13 +1,12 @@ if Backbone? class @DiscussionThreadProfileView extends Backbone.View render: -> - @template = DiscussionUtil.getTemplate("_profile_thread") @convertMath() @abbreviateBody() params = $.extend(@model.toJSON(),{permalink: @model.urlFor('retrieve')}) if not @model.get('anonymous') params = $.extend(params, user:{username: @model.username, user_url: @model.user_url}) - @$el.html(Mustache.render(@template, params)) + @$el.html(_.template($("#profile-thread-template").html())(params)) @$("span.timeago").timeago() element = @$(".post-body") if MathJax? diff --git a/common/static/coffee/src/discussion/views/discussion_user_profile_view.coffee b/common/static/coffee/src/discussion/views/discussion_user_profile_view.coffee index 94cb5f1c63..77cfd7df4f 100644 --- a/common/static/coffee/src/discussion/views/discussion_user_profile_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_user_profile_view.coffee @@ -12,15 +12,13 @@ if Backbone? @discussion.reset(@collection, {silent: false}) render: () => - profileTemplate = $("script#_user_profile").html() - @$el.html(Mustache.render(profileTemplate, {threads: @discussion.models})) + @$el.html(_.template($("#user-profile-template").html())({threads: @discussion.models})) @discussion.map (thread) -> new DiscussionThreadProfileView(el: @$("article#thread_#{thread.id}"), model: thread).render() baseUri = URI(window.location).removeSearch("page") pageUrlFunc = (page) -> baseUri.clone().addSearch("page", page) paginationParams = DiscussionUtil.getPaginationParams(@page, @numPages, pageUrlFunc) - paginationTemplate = $("script#_pagination").html() - @$el.find(".pagination").html(Mustache.render(paginationTemplate, paginationParams)) + @$el.find(".pagination").html(_.template($("#pagination-template").html())(paginationParams)) changePage: (event) -> event.preventDefault() diff --git a/common/static/common/templates/discussion/inline-discussion.underscore b/common/static/common/templates/discussion/inline-discussion.underscore new file mode 100644 index 0000000000..42f7f2f2f2 --- /dev/null +++ b/common/static/common/templates/discussion/inline-discussion.underscore @@ -0,0 +1,13 @@ +
+
+ +
+ <% _.each(threads, function(thread) { %> +
+
+ <% }); %> +
+ +
+
+
diff --git a/common/static/common/templates/discussion/pagination.underscore b/common/static/common/templates/discussion/pagination.underscore new file mode 100644 index 0000000000..d770d9d8c2 --- /dev/null +++ b/common/static/common/templates/discussion/pagination.underscore @@ -0,0 +1,31 @@ + diff --git a/common/static/common/templates/discussion/profile-thread.underscore b/common/static/common/templates/discussion/profile-thread.underscore new file mode 100644 index 0000000000..6070c63e0b --- /dev/null +++ b/common/static/common/templates/discussion/profile-thread.underscore @@ -0,0 +1,24 @@ +
+
+
+

<%- title %>

+

+ <% if (user) { %> + <%- user.username %> + <% } else { %> + <%- gettext("anonymous") %> + <% } %> + + <%- created_at %> + +

+
+
<%= abbreviatedBody %>
+
+
+ <%- gettext("View discussion") %> +
+ +
diff --git a/common/static/common/templates/discussion/user-profile.underscore b/common/static/common/templates/discussion/user-profile.underscore new file mode 100644 index 0000000000..0eeda55723 --- /dev/null +++ b/common/static/common/templates/discussion/user-profile.underscore @@ -0,0 +1,7 @@ +

<%- gettext("Active Threads") %>

+
+ <% _.each(threads, function(thread) { %> +
+ <% }); %> +
+
diff --git a/lms/djangoapps/django_comment_client/helpers.py b/lms/djangoapps/django_comment_client/helpers.py deleted file mode 100644 index c0f7d751e0..0000000000 --- a/lms/djangoapps/django_comment_client/helpers.py +++ /dev/null @@ -1,29 +0,0 @@ -from django.conf import settings -from mako.template import Template - -import os - - -def include_mustache_templates(): - mustache_dir = settings.PROJECT_ROOT / 'templates' / 'discussion' / 'mustache' - - def is_valid_file_name(file_name): - return file_name.endswith('.mustache') - - def read_file(file_name): - return open(mustache_dir / file_name, "r").read().decode('utf-8') - - def template_id_from_file_name(file_name): - return file_name.rpartition('.')[0] - - def process_mako(template_content): - return Template(template_content).render_unicode() - - def make_script_tag(id, content): - return u"".format(id, content) - - return u'\n'.join( - make_script_tag(template_id_from_file_name(file_name), process_mako(read_file(file_name))) - for file_name in os.listdir(mustache_dir) - if is_valid_file_name(file_name) - ) diff --git a/lms/templates/discussion/_js_body_dependencies.html b/lms/templates/discussion/_js_body_dependencies.html index 86265c7cb4..801e275ebf 100644 --- a/lms/templates/discussion/_js_body_dependencies.html +++ b/lms/templates/discussion/_js_body_dependencies.html @@ -1,4 +1 @@ -<%! from django_comment_client.helpers import include_mustache_templates %> - <%include file="/mathjax_include.html" /> -${include_mustache_templates()} diff --git a/lms/templates/discussion/_js_head_dependencies.html b/lms/templates/discussion/_js_head_dependencies.html index 9cdd220d29..5271c8ba40 100644 --- a/lms/templates/discussion/_js_head_dependencies.html +++ b/lms/templates/discussion/_js_head_dependencies.html @@ -9,7 +9,6 @@ - diff --git a/lms/templates/discussion/_recent_active_posts.html b/lms/templates/discussion/_recent_active_posts.html index eddc5072a0..2d032c2b0a 100644 --- a/lms/templates/discussion/_recent_active_posts.html +++ b/lms/templates/discussion/_recent_active_posts.html @@ -1,6 +1,6 @@ <%! from django.utils.translation import ugettext as _ -import django_comment_client.helpers as helpers +from django_comment_client.utils import permalink %> % if recent_active_threads: @@ -11,7 +11,7 @@ import django_comment_client.helpers as helpers
    % for thread in recent_active_threads: -
  1. ${thread['title'] | h} ${thread['votes']['point'] | h}
  2. +
  3. ${thread['title'] | h} ${thread['votes']['point'] | h}
  4. % endfor
      diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index 35e35785d3..7056157416 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -6,7 +6,16 @@ window.PLATFORM_NAME = ${json.dumps(settings.PLATFORM_NAME)}; window.ENABLE_DISCUSSION_HOME_PANEL = ${json.dumps(settings.FEATURES.get('ENABLE_DISCUSSION_HOME_PANEL', False))}; -% for template_name in ['thread', 'thread-show', 'thread-edit', 'thread-response', 'thread-response-show', 'thread-response-edit', 'response-comment-show', 'response-comment-edit', 'thread-list-item', 'discussion-home', 'search-alert', 'new-post', 'thread-type', 'new-post-menu-entry', 'new-post-menu-category', 'topic', 'post-user-display']: +<% +template_names = [ + 'thread', 'thread-show', 'thread-edit', 'thread-response', 'thread-response-show', 'thread-response-edit', + 'response-comment-show', 'response-comment-edit', 'thread-list-item', 'discussion-home', 'search-alert', + 'new-post', 'thread-type', 'new-post-menu-entry', 'new-post-menu-category', 'topic', 'post-user-display', + 'inline-discussion', 'pagination', 'user-profile', 'profile-thread' +] +%> + +% for template_name in template_names: diff --git a/lms/templates/discussion/index.html b/lms/templates/discussion/index.html index 53497a48a2..8b074b8190 100644 --- a/lms/templates/discussion/index.html +++ b/lms/templates/discussion/index.html @@ -2,7 +2,6 @@ <%namespace name='static' file='../static_content.html'/> <%! from django.utils.translation import ugettext as _ -import django_comment_client.helpers as helpers from django.template.defaultfilters import escapejs from django.core.urlresolvers import reverse %> diff --git a/lms/templates/discussion/mustache/_inline_discussion.mustache b/lms/templates/discussion/mustache/_inline_discussion.mustache deleted file mode 100644 index 56f22b0538..0000000000 --- a/lms/templates/discussion/mustache/_inline_discussion.mustache +++ /dev/null @@ -1,15 +0,0 @@ -<%! from django.utils.translation import ugettext as _ %> - -
      -
      - -
      - {{#threads}} -
      -
      - {{/threads}} -
      - -
      -
      -
      diff --git a/lms/templates/discussion/mustache/_pagination.mustache b/lms/templates/discussion/mustache/_pagination.mustache deleted file mode 100644 index 11389e3862..0000000000 --- a/lms/templates/discussion/mustache/_pagination.mustache +++ /dev/null @@ -1,34 +0,0 @@ -<%! from django.utils.translation import ugettext as _ %> - - - diff --git a/lms/templates/discussion/mustache/_profile_thread.mustache b/lms/templates/discussion/mustache/_profile_thread.mustache deleted file mode 100644 index e666f34cdd..0000000000 --- a/lms/templates/discussion/mustache/_profile_thread.mustache +++ /dev/null @@ -1,27 +0,0 @@ -<%! from django.utils.translation import ugettext as _ %> - -
      -
      -
      -

      {{title}}

      -

      - {{#user}} - {{username}} - {{/user}} - {{^user}} - ${_("anonymous")} - {{/user}} - - {{created_at}} - -

      -
      -
      {{{abbreviatedBody}}}
      -
      -
      - ${_("View discussion")} -
      - -
      diff --git a/lms/templates/discussion/mustache/_user_profile.mustache b/lms/templates/discussion/mustache/_user_profile.mustache deleted file mode 100644 index 3e0fcd516d..0000000000 --- a/lms/templates/discussion/mustache/_user_profile.mustache +++ /dev/null @@ -1,9 +0,0 @@ -<%! from django.utils.translation import ugettext as _ %> - -

      ${_("Active Threads")}

      -
      - {{#threads}} -
      - {{/threads}} -
      -