From ef9c018bed870a62a9637c26a379dddaffeb3533 Mon Sep 17 00:00:00 2001 From: Iain Bryson <iain@iain-bryson.ca> Date: Wed, 13 Jul 2016 21:51:33 -0700 Subject: [PATCH] Move content folders. Refactoring rendering a bit. Simplify bower file. Enable MD-rendering in the enote environment. --- Dockerfile | 4 ++ app/assets/javascripts/application.js | 7 +-- app/assets/javascripts/home.coffee | 1 + app/assets/javascripts/render.js | 71 +++++++++++++++++++++++++++ app/controllers/home_controller.rb | 12 +++-- app/views/home/index.html.erb | 54 ++------------------ bower.json | 2 - config/application.rb | 2 + dtu-auth/lib/dtu_auth.rb | 2 +- 9 files changed, 95 insertions(+), 60 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ab95fe..1dcd00c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,10 @@ COPY . /dtu-course/app RUN rm -rf tmp RUN mkdir tmp +# install bower +RUN npm install -g bower +RUN bower install --allow-root + #RUN mkdir -p ~/.ssh #RUN cp /dtu-data/known_hosts ~/.ssh #RUN ssh-keygen -R github.com diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 93a3095..cffd73d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,7 +10,6 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // -//= require underscore //= require jquery //= require jquery-ujs //= require MathJax @@ -20,6 +19,8 @@ //= require pagedown-extra/pagedown/Markdown.Editor.js //= require pagedown-extra/Markdown.Extra.js //= require turbolinks -//= require_tree . //= require bootstrap -//= require mathjax \ No newline at end of file +//= require mathjax +//= require_tree . + +//= require render \ No newline at end of file diff --git a/app/assets/javascripts/home.coffee b/app/assets/javascripts/home.coffee index 24f83d1..43d766d 100644 --- a/app/assets/javascripts/home.coffee +++ b/app/assets/javascripts/home.coffee @@ -1,3 +1,4 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://coffeescript.org/ + diff --git a/app/assets/javascripts/render.js b/app/assets/javascripts/render.js index e69de29..06e5fde 100644 --- a/app/assets/javascripts/render.js +++ b/app/assets/javascripts/render.js @@ -0,0 +1,71 @@ +function renderPage() { + "use strict"; + + console.log("rendering"); + MathJax.Hub.Config({ + skipStartupTypeset: true, + "HTML-CSS": { + preferredFont: "TeX", + availableFonts: [ + "TeX" + ], + linebreaks: { + automatic: true + }, + EqnChunk: 10, + imageFont: null + }, + root: '/assets/MathJax', + tex2jax: { + inlineMath: [ + ["$", "$"], + ["\\\\\\\\(", "\\\\\\\\)"] + ], + displayMath: [ + ["$$", "$$"], + ["\\\\[", "\\\\]"] + ], + processEscapes: true + }, + TeX: { + noUndefined: { + attributes: { + mathcolor: "red", + mathbackground: "#FFEEEE", + mathsize: "90%" + } + }, + Safe: { + allow: { + URLs: "safe", + classes: "safe", + cssIDs: "safe", + styles: "safe", + fontsize: "all" + } + } + }, + messageStyle: "none" + }); + + + var converter = new Markdown.Converter(); + Markdown.Extra.init(converter, { + table_class: "table table-striped" + }); + mathJax.onPagedownConfigure(converter); + converter.hooks.chain("postConversion", function(x) { + return x + }); + + if (typeof renderCoursePage === "function") { + renderCoursePage(converter); + } + + MathJax.Hub.Queue( + ["Typeset", MathJax.Hub, "content"] + ); +}; + + +$(document).on('ready page:load', renderPage); \ No newline at end of file diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 0eb7bdd..cd2cb5f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -5,9 +5,15 @@ class HomeController < ApplicationController :right_md, :course) def index - @course = "00000" + @course = Rails.configuration.dtu_data[:course] - @left_md = File.read(File.join(DTUAuth::AuthorizationManager.instance.dtu_data_root, @course+'-content', 'Frontpage-left.md')) - @right_md = File.read(File.join(DTUAuth::AuthorizationManager.instance.dtu_data_root, @course+'-content', 'Frontpage-right.md')) + @left_path = File.join(DTUAuth::AuthorizationManager.instance.dtu_data_root, @course+'-content', 'Frontpage-left.md') + @right_path = File.join(DTUAuth::AuthorizationManager.instance.dtu_data_root, @course+'-content', 'Frontpage-right.md') + + Rails.logger.debug(@left_path) + Rails.logger.debug(@right_path) + + @left_md = File.read(@left_path) + @right_md = File.read(@right_path) end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 5ac4d0c..e58ce7a 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -67,60 +67,12 @@ </div> <script> -$(document).on('ready page:load', function() { - "use strict"; -MathJax.Hub.Config({ - skipStartupTypeset: true, - "HTML-CSS": { - preferredFont: "TeX", - availableFonts: [ - "TeX" - ], - linebreaks: { - automatic: true - }, - EqnChunk: 10, - imageFont: null - }, - root: '/assets/MathJax', - tex2jax: { inlineMath: [["$","$"],["\\\\\\\\(","\\\\\\\\)"]], displayMath: [["$$","$$"],["\\\\[","\\\\]"]], processEscapes: true }, - TeX: { - noUndefined: { - attributes: { - mathcolor: "red", - mathbackground: "#FFEEEE", - mathsize: "90%" - } - }, - Safe: { - allow: { - URLs: "safe", - classes: "safe", - cssIDs: "safe", - styles: "safe", - fontsize: "all" - } - } - }, - messageStyle: "none" -}); - - var converter = new Markdown.Converter(); -Markdown.Extra.init(converter, { - table_class: "table table-striped" -}); -mathJax.onPagedownConfigure(converter); -converter.hooks.chain("postConversion", function(x) { - return x -}); -$('.panel-body').html(converter.makeHtml("<%== escape_javascript @left_md %>)")); +function renderCoursePage(converter) { + $('.panel-body').html(converter.makeHtml("<%== escape_javascript @left_md %>)")); $('#content').html(converter.makeHtml("<%== escape_javascript @right_md %>)")); - MathJax.Hub.Queue( - ["Typeset", MathJax.Hub, "content"] - ); - }); +} </script> </div> diff --git a/bower.json b/bower.json index ae15ea5..fc5701b 100644 --- a/bower.json +++ b/bower.json @@ -23,8 +23,6 @@ "bootstrap": "3.0.3", "jquery": "2.0.3", "jquery-ujs": "1.2.1", - "underscore": "1.5.1", - "requirejs": "~2.1.11", "require-css": "0.1.5", "require-less": "0.1.2", "pagedown-extra": "https://github.com/jmcmanus/pagedown-extra.git#ea782c3d11eb78f57d00aa819527338996a70721", diff --git a/config/application.rb b/config/application.rb index fce906c..1ea0e53 100644 --- a/config/application.rb +++ b/config/application.rb @@ -31,5 +31,7 @@ module DTUCourseWebsite # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de + + config.dtu_data = {:course => ENV['COURSE_NAME'], :root_path => ENV['DTU_DATA_ROOT'] || "/dtu-data"} end end diff --git a/dtu-auth/lib/dtu_auth.rb b/dtu-auth/lib/dtu_auth.rb index 8433ac0..7736bec 100644 --- a/dtu-auth/lib/dtu_auth.rb +++ b/dtu-auth/lib/dtu_auth.rb @@ -19,7 +19,7 @@ module DTUAuth def load - self.dtu_data_root = Rails.root.join('../dtu-data/') + self.dtu_data_root = Rails.root.join(Rails.configuration.dtu_data[:root_path]) Rails.logger.debug "Initializing auth module" Rails.logger.info "Using auth data from #{dtu_data_root}" -- GitLab