diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 7e0db8c07..e8dcf07dd 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,11 +1,17 @@ module.exports = (grunt) -> + importHTML = (filename) -> + "\"\"\"#{grunt.file.read("html/#{filename}.html").replace(/^\s+|\s+$ grunt.config 'pkg' + get: -> + pkg = grunt.config 'pkg' + pkg.importHTML = importHTML + pkg enumerable: true ) coffee: diff --git a/src/General/Header.coffee b/src/General/Header.coffee index 7e401e5a9..c94e697ae 100644 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -2,9 +2,7 @@ Header = init: -> headerEl = $.el 'div', id: 'header' - innerHTML: """ - <%= grunt.file.read('html/General/Header.html').replace(/>\s+<').trim() %> - """ + innerHTML: <%= importHTML('General/Header') %> @bar = $ '#header-bar', headerEl @toggle = $ '#toggle-header-bar', @bar diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 0915f01c4..c930bb3d0 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -48,9 +48,7 @@ Index = Index.root = $.el 'div', className: 'board' Index.pagelist = $.el 'div', className: 'pagelist' - innerHTML: """ - <%= grunt.file.read('html/General/Index-pagelist.html').replace(/>\s+<').trim() %> - """ + innerHTML: <%= importHTML('General/Index-pagelist') %> $.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), -> $.replace $('.board'), Index.root $.replace $('.pagelist'), Index.pagelist diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index 65f2a5094..4c0499e4c 100644 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -61,9 +61,7 @@ Settings = return if Settings.dialog $.event 'CloseMenu' - html = """ - <%= grunt.file.read('html/General/Settings.html').replace(/>\s+<').trim() %> - """ + html = <%= importHTML('General/Settings') %> Settings.dialog = overlay = $.el 'div', id: 'overlay' @@ -113,9 +111,7 @@ Settings = section.scrollTop = 0 main: (section) -> - section.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-Main.html').replace(/>\s+<').trim() %> - """ + section.innerHTML = <%= importHTML('General/Settings-section-Main') %> $.on $('.export', section), 'click', Settings.export $.on $('.import', section), 'click', Settings.import $.on $('input', section), 'change', Settings.onImport @@ -290,9 +286,7 @@ Settings = data filter: (section) -> - section.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-Filter.html').replace(/>\s+<').trim() %> - """ + section.innerHTML = <%= importHTML('General/Settings-section-Filter') %> select = $ 'select', section $.on select, 'change', Settings.selectFilter Settings.selectFilter.call select @@ -309,32 +303,24 @@ Settings = $.on ta, 'change', $.cb.value $.add div, ta return - div.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-Filter-guide.html').replace(/>\s+<').trim() %> - """ + div.innerHTML = <%= importHTML('General/Settings-section-Filter-guide') %> qr: (section) -> - section.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-QR.html').replace(/>\s+<').trim() %> - """ + section.innerHTML = <%= importHTML('General/Settings-section-QR') %> ta = $ 'textarea', section $.get 'QR.personas', Conf['QR.personas'], (item) -> ta.value = item['QR.personas'] $.on ta, 'change', $.cb.value sauce: (section) -> - section.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-Sauce.html').replace(/>\s+<').trim() %> - """ + section.innerHTML = <%= importHTML('General/Settings-section-Sauce') %> ta = $ 'textarea', section $.get 'sauces', Conf['sauces'], (item) -> ta.value = item['sauces'] $.on ta, 'change', $.cb.value rice: (section) -> - section.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-Rice.html').replace(/>\s+<').trim() %> - """ + section.innerHTML = <%= importHTML('General/Settings-section-Rice') %> items = {} inputs = {} for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss'] @@ -395,9 +381,7 @@ Settings = CustomCSS.update() archives: (section) -> - section.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-Archives.html').replace(/>\s+<').trim() %> - """ + section.innerHTML = <%= importHTML('General/Settings-section-Archives') %> showLastUpdateTime = (time) -> $('time', section).textContent = new Date(time).toLocaleString() @@ -470,9 +454,7 @@ Settings = $.set 'selectedArchives', selectedArchives keybinds: (section) -> - section.innerHTML = """ - <%= grunt.file.read('html/General/Settings-section-Keybinds.html').replace(/>\s+<').trim() %> - """ + section.innerHTML = <%= importHTML('General/Settings-section-Keybinds') %> tbody = $ 'tbody', section items = {} inputs = {} diff --git a/src/Monitoring/Favicon.coffee b/src/Monitoring/Favicon.coffee index 806134034..6085a6f2c 100644 --- a/src/Monitoring/Favicon.coffee +++ b/src/Monitoring/Favicon.coffee @@ -45,5 +45,5 @@ Favicon = Favicon.unread = Favicon.unreadNSFW Favicon.unreadY = Favicon.unreadNSFWY - dead: 'data:image/gif;base64,<%= grunt.file.read("img/favicons/dead.gif", {encoding: "base64"}) %>' - logo: 'data:image/png;base64,<%= grunt.file.read("img/icon128.png", {encoding: "base64"}) %>' + dead: 'data:image/gif;base64,<%= grunt.file.read("img/favicons/dead.gif", {encoding: "base64"}) %>' + logo: 'data:image/png;base64,<%= grunt.file.read("img/icon128.png", {encoding: "base64"}) %>' diff --git a/src/Monitoring/ThreadStats.coffee b/src/Monitoring/ThreadStats.coffee index f80154cae..89d1be0c8 100644 --- a/src/Monitoring/ThreadStats.coffee +++ b/src/Monitoring/ThreadStats.coffee @@ -1,9 +1,7 @@ ThreadStats = init: -> return if g.VIEW isnt 'thread' or !Conf['Thread Stats'] - @dialog = UI.dialog 'thread-stats', 'bottom: 0; left: 0;', """ - <%= grunt.file.read('html/Monitoring/ThreadStats.html').replace(/>\s+<').trim() %> - """ + @dialog = UI.dialog 'thread-stats', 'bottom: 0; left: 0;', <%= importHTML('Monitoring/ThreadStats') %> @postCountEl = $ '#post-count', @dialog @fileCountEl = $ '#file-count', @dialog diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 8e9c68779..602f45383 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -7,9 +7,7 @@ ThreadUpdater = checked = if Conf[name] then 'checked' else '' html += "
" - html = """ - <%= grunt.file.read('html/Monitoring/ThreadUpdater.html').replace(/>\s+<').trim() %> - """ + html = <%= importHTML('Monitoring/ThreadUpdater') %> @dialog = UI.dialog 'updater', 'bottom: 0; right: 0;', html @timer = $ '#update-timer', @dialog diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index 76abbf521..3b021d5a7 100644 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -3,9 +3,7 @@ ThreadWatcher = return if !Conf['Thread Watcher'] @db = new DataBoard 'watchedThreads', @refresh, true - @dialog = UI.dialog 'thread-watcher', 'top: 50px; left: 0px;', """ - <%= grunt.file.read('html/Monitoring/ThreadWatcher.html').replace(/>\s+<').trim() %> - """ + @dialog = UI.dialog 'thread-watcher', 'top: 50px; left: 0px;', <%= importHTML('Monitoring/ThreadWatcher') %> @status = $ '#watcher-status', @dialog @list = @dialog.lastElementChild diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index 9f81f22a3..7a8f829ea 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -820,9 +820,7 @@ QR = 'new' dialog: -> - dialog = UI.dialog 'qr', 'top:0;right:0;', """ - <%= grunt.file.read('html/Posting/QR.html').replace(/>\s+<').trim() %> - """ + dialog = UI.dialog 'qr', 'top:0;right:0;', <%= importHTML('Posting/QR') %> QR.nodes = nodes = el: dialog