Create importHTML function, and use it.

This commit is contained in:
Mayhem 2013-11-01 23:08:31 +01:00
parent 47710a7c6e
commit bc72f0f763
9 changed files with 24 additions and 48 deletions

View File

@ -1,11 +1,17 @@
module.exports = (grunt) -> module.exports = (grunt) ->
importHTML = (filename) ->
"\"\"\"#{grunt.file.read("html/#{filename}.html").replace(/^\s+|\s+$</gm, '').replace(/\n/g, '')}\"\"\""
# Project configuration. # Project configuration.
grunt.initConfig grunt.initConfig
pkg: grunt.file.readJSON 'package.json' pkg: grunt.file.readJSON 'package.json'
concat: concat:
options: process: Object.create(null, data: options: process: Object.create(null, data:
get: -> grunt.config 'pkg' get: ->
pkg = grunt.config 'pkg'
pkg.importHTML = importHTML
pkg
enumerable: true enumerable: true
) )
coffee: coffee:

View File

@ -2,9 +2,7 @@ Header =
init: -> init: ->
headerEl = $.el 'div', headerEl = $.el 'div',
id: 'header' id: 'header'
innerHTML: """ innerHTML: <%= importHTML('General/Header') %>
<%= grunt.file.read('html/General/Header.html').replace(/>\s+</g, '><').trim() %>
"""
@bar = $ '#header-bar', headerEl @bar = $ '#header-bar', headerEl
@toggle = $ '#toggle-header-bar', @bar @toggle = $ '#toggle-header-bar', @bar

View File

@ -48,9 +48,7 @@ Index =
Index.root = $.el 'div', className: 'board' Index.root = $.el 'div', className: 'board'
Index.pagelist = $.el 'div', Index.pagelist = $.el 'div',
className: 'pagelist' className: 'pagelist'
innerHTML: """ innerHTML: <%= importHTML('General/Index-pagelist') %>
<%= grunt.file.read('html/General/Index-pagelist.html').replace(/>\s+</g, '><').trim() %>
"""
$.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), -> $.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), ->
$.replace $('.board'), Index.root $.replace $('.board'), Index.root
$.replace $('.pagelist'), Index.pagelist $.replace $('.pagelist'), Index.pagelist

View File

@ -61,9 +61,7 @@ Settings =
return if Settings.dialog return if Settings.dialog
$.event 'CloseMenu' $.event 'CloseMenu'
html = """ html = <%= importHTML('General/Settings') %>
<%= grunt.file.read('html/General/Settings.html').replace(/>\s+</g, '><').trim() %>
"""
Settings.dialog = overlay = $.el 'div', Settings.dialog = overlay = $.el 'div',
id: 'overlay' id: 'overlay'
@ -113,9 +111,7 @@ Settings =
section.scrollTop = 0 section.scrollTop = 0
main: (section) -> main: (section) ->
section.innerHTML = """ section.innerHTML = <%= importHTML('General/Settings-section-Main') %>
<%= grunt.file.read('html/General/Settings-section-Main.html').replace(/>\s+</g, '><').trim() %>
"""
$.on $('.export', section), 'click', Settings.export $.on $('.export', section), 'click', Settings.export
$.on $('.import', section), 'click', Settings.import $.on $('.import', section), 'click', Settings.import
$.on $('input', section), 'change', Settings.onImport $.on $('input', section), 'change', Settings.onImport
@ -290,9 +286,7 @@ Settings =
data data
filter: (section) -> filter: (section) ->
section.innerHTML = """ section.innerHTML = <%= importHTML('General/Settings-section-Filter') %>
<%= grunt.file.read('html/General/Settings-section-Filter.html').replace(/>\s+</g, '><').trim() %>
"""
select = $ 'select', section select = $ 'select', section
$.on select, 'change', Settings.selectFilter $.on select, 'change', Settings.selectFilter
Settings.selectFilter.call select Settings.selectFilter.call select
@ -309,32 +303,24 @@ Settings =
$.on ta, 'change', $.cb.value $.on ta, 'change', $.cb.value
$.add div, ta $.add div, ta
return return
div.innerHTML = """ div.innerHTML = <%= importHTML('General/Settings-section-Filter-guide') %>
<%= grunt.file.read('html/General/Settings-section-Filter-guide.html').replace(/>\s+</g, '><').trim() %>
"""
qr: (section) -> qr: (section) ->
section.innerHTML = """ section.innerHTML = <%= importHTML('General/Settings-section-QR') %>
<%= grunt.file.read('html/General/Settings-section-QR.html').replace(/>\s+</g, '><').trim() %>
"""
ta = $ 'textarea', section ta = $ 'textarea', section
$.get 'QR.personas', Conf['QR.personas'], (item) -> $.get 'QR.personas', Conf['QR.personas'], (item) ->
ta.value = item['QR.personas'] ta.value = item['QR.personas']
$.on ta, 'change', $.cb.value $.on ta, 'change', $.cb.value
sauce: (section) -> sauce: (section) ->
section.innerHTML = """ section.innerHTML = <%= importHTML('General/Settings-section-Sauce') %>
<%= grunt.file.read('html/General/Settings-section-Sauce.html').replace(/>\s+</g, '><').trim() %>
"""
ta = $ 'textarea', section ta = $ 'textarea', section
$.get 'sauces', Conf['sauces'], (item) -> $.get 'sauces', Conf['sauces'], (item) ->
ta.value = item['sauces'] ta.value = item['sauces']
$.on ta, 'change', $.cb.value $.on ta, 'change', $.cb.value
rice: (section) -> rice: (section) ->
section.innerHTML = """ section.innerHTML = <%= importHTML('General/Settings-section-Rice') %>
<%= grunt.file.read('html/General/Settings-section-Rice.html').replace(/>\s+</g, '><').trim() %>
"""
items = {} items = {}
inputs = {} inputs = {}
for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss'] for name in ['boardnav', 'time', 'backlink', 'fileInfo', 'favicon', 'usercss']
@ -395,9 +381,7 @@ Settings =
CustomCSS.update() CustomCSS.update()
archives: (section) -> archives: (section) ->
section.innerHTML = """ section.innerHTML = <%= importHTML('General/Settings-section-Archives') %>
<%= grunt.file.read('html/General/Settings-section-Archives.html').replace(/>\s+</g, '><').trim() %>
"""
showLastUpdateTime = (time) -> showLastUpdateTime = (time) ->
$('time', section).textContent = new Date(time).toLocaleString() $('time', section).textContent = new Date(time).toLocaleString()
@ -470,9 +454,7 @@ Settings =
$.set 'selectedArchives', selectedArchives $.set 'selectedArchives', selectedArchives
keybinds: (section) -> keybinds: (section) ->
section.innerHTML = """ section.innerHTML = <%= importHTML('General/Settings-section-Keybinds') %>
<%= grunt.file.read('html/General/Settings-section-Keybinds.html').replace(/>\s+</g, '><').trim() %>
"""
tbody = $ 'tbody', section tbody = $ 'tbody', section
items = {} items = {}
inputs = {} inputs = {}

View File

@ -45,5 +45,5 @@ Favicon =
Favicon.unread = Favicon.unreadNSFW Favicon.unread = Favicon.unreadNSFW
Favicon.unreadY = Favicon.unreadNSFWY Favicon.unreadY = Favicon.unreadNSFWY
dead: 'data:image/gif;base64,<%= grunt.file.read("img/favicons/dead.gif", {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"}) %>' logo: 'data:image/png;base64,<%= grunt.file.read("img/icon128.png", {encoding: "base64"}) %>'

View File

@ -1,9 +1,7 @@
ThreadStats = ThreadStats =
init: -> init: ->
return if g.VIEW isnt 'thread' or !Conf['Thread Stats'] return if g.VIEW isnt 'thread' or !Conf['Thread Stats']
@dialog = UI.dialog 'thread-stats', 'bottom: 0; left: 0;', """ @dialog = UI.dialog 'thread-stats', 'bottom: 0; left: 0;', <%= importHTML('Monitoring/ThreadStats') %>
<%= grunt.file.read('html/Monitoring/ThreadStats.html').replace(/>\s+</g, '><').trim() %>
"""
@postCountEl = $ '#post-count', @dialog @postCountEl = $ '#post-count', @dialog
@fileCountEl = $ '#file-count', @dialog @fileCountEl = $ '#file-count', @dialog

View File

@ -7,9 +7,7 @@ ThreadUpdater =
checked = if Conf[name] then 'checked' else '' checked = if Conf[name] then 'checked' else ''
html += "<div><label title='#{conf[1]}'><input name='#{name}' type=checkbox #{checked}> #{name}</label></div>" html += "<div><label title='#{conf[1]}'><input name='#{name}' type=checkbox #{checked}> #{name}</label></div>"
html = """ html = <%= importHTML('Monitoring/ThreadUpdater') %>
<%= grunt.file.read('html/Monitoring/ThreadUpdater.html').replace(/>\s+</g, '><').trim() %>
"""
@dialog = UI.dialog 'updater', 'bottom: 0; right: 0;', html @dialog = UI.dialog 'updater', 'bottom: 0; right: 0;', html
@timer = $ '#update-timer', @dialog @timer = $ '#update-timer', @dialog

View File

@ -3,9 +3,7 @@ ThreadWatcher =
return if !Conf['Thread Watcher'] return if !Conf['Thread Watcher']
@db = new DataBoard 'watchedThreads', @refresh, true @db = new DataBoard 'watchedThreads', @refresh, true
@dialog = UI.dialog 'thread-watcher', 'top: 50px; left: 0px;', """ @dialog = UI.dialog 'thread-watcher', 'top: 50px; left: 0px;', <%= importHTML('Monitoring/ThreadWatcher') %>
<%= grunt.file.read('html/Monitoring/ThreadWatcher.html').replace(/>\s+</g, '><').trim() %>
"""
@status = $ '#watcher-status', @dialog @status = $ '#watcher-status', @dialog
@list = @dialog.lastElementChild @list = @dialog.lastElementChild

View File

@ -820,9 +820,7 @@ QR =
'new' 'new'
dialog: -> dialog: ->
dialog = UI.dialog 'qr', 'top:0;right:0;', """ dialog = UI.dialog 'qr', 'top:0;right:0;', <%= importHTML('Posting/QR') %>
<%= grunt.file.read('html/Posting/QR.html').replace(/>\s+</g, '><').trim() %>
"""
QR.nodes = nodes = QR.nodes = nodes =
el: dialog el: dialog