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

View File

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

View File

@ -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+</g, '><').trim() %>
"""
innerHTML: <%= importHTML('General/Index-pagelist') %>
$.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), ->
$.replace $('.board'), Index.root
$.replace $('.pagelist'), Index.pagelist

View File

@ -61,9 +61,7 @@ Settings =
return if Settings.dialog
$.event 'CloseMenu'
html = """
<%= grunt.file.read('html/General/Settings.html').replace(/>\s+</g, '><').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+</g, '><').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+</g, '><').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+</g, '><').trim() %>
"""
div.innerHTML = <%= importHTML('General/Settings-section-Filter-guide') %>
qr: (section) ->
section.innerHTML = """
<%= grunt.file.read('html/General/Settings-section-QR.html').replace(/>\s+</g, '><').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+</g, '><').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+</g, '><').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+</g, '><').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+</g, '><').trim() %>
"""
section.innerHTML = <%= importHTML('General/Settings-section-Keybinds') %>
tbody = $ 'tbody', section
items = {}
inputs = {}

View File

@ -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"}) %>'

View File

@ -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+</g, '><').trim() %>
"""
@dialog = UI.dialog 'thread-stats', 'bottom: 0; left: 0;', <%= importHTML('Monitoring/ThreadStats') %>
@postCountEl = $ '#post-count', @dialog
@fileCountEl = $ '#file-count', @dialog

View File

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

View File

@ -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+</g, '><').trim() %>
"""
@dialog = UI.dialog 'thread-watcher', 'top: 50px; left: 0px;', <%= importHTML('Monitoring/ThreadWatcher') %>
@status = $ '#watcher-status', @dialog
@list = @dialog.lastElementChild

View File

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