From 07ae8865690d8f6b54ef0b09d4a3c49def616428 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Sat, 13 Feb 2016 13:37:45 -0800 Subject: [PATCH] =?UTF-8?q?[=E2=98=85]=20Serving=20up=20the=20require.js?= =?UTF-8?q?=20stuff=20properly,=20now=20getting=20transactions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 12 +++++++++++- main.hy | 27 ++++++++++++++++++++++++--- source/index.coffee | 7 +++++-- source/index.haml | 3 ++- source/officehours.coffee | 18 ++++++++---------- 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index ad3e844..6d2abf0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,12 @@ -all: static/index.html static/index.js static/officehours.js +SOURCES = source/*.coffee source/*.haml main.hy + +all: static/index.html static/index.js static/officehours.js main.py + +# Needed because Flask's "debugger" setting doesn't grok +# Hy directly. Nuisance! + +main.py: + hy2py main.hy > main.py static/%.html: source/%.haml haml --unix-newlines --no-escape-attrs --double-quote-attributes $< > $@ @@ -9,4 +17,6 @@ static/%.js: source/%.coffee clean: rm static/*.html static/*.js +watch: + while inotifywait $(SOURCES); do clear ; make all ; done diff --git a/main.hy b/main.hy index 9a858a4..fbf358b 100644 --- a/main.hy +++ b/main.hy @@ -26,9 +26,30 @@ (send-from-directory "static" "index.html"))) (with-decorator - (.route app "/oh/hours/") - (print start) - (jsonify { start: start })) + (.route app "/index.js") + (defn index [] + (send-from-directory "static" "index.js"))) + +(with-decorator + (.route app "/officehours.js") + (defn officehours [] + (send-from-directory "static" "officehours.js"))) + +(with-decorator + (.route app "/lib/") + (defn lib [path] + (send-from-directory "static/lib" path))) + +(with-decorator + (.route app "/oh/hours/") + (defn defhours [start] + (jsonify { "start" start }))) + +(with-decorator + (.route app "/oh/hours/") + (defn hours [start] + (print start) + (jsonify { "start" start }))) ;(with-decorator ; (.route app "/") diff --git a/source/index.coffee b/source/index.coffee index 1ed018c..e071085 100644 --- a/source/index.coffee +++ b/source/index.coffee @@ -4,9 +4,12 @@ require.config 'jquery': './lib/jquery.min' 'backbone': './lib/backbone-min' 'json2': './lib/json2' + 'domReady': './lib/domReady' shim: + json2: + exports: 'JSON' 'backbone': ['json2'] require ['backbone', 'json2'], () -> - require ['officehours'], (start) -> - $(start) + require ['officehours', 'domReady'], (start, ready) -> + ready(start) diff --git a/source/index.haml b/source/index.haml index ce5e8de..c8029a6 100644 --- a/source/index.haml +++ b/source/index.haml @@ -3,7 +3,8 @@ %head %title Appointment Calendar %link{:href => "/static/officehours.css", :rel => "stylesheet", :type => "text/css"} - %script{:src => "static/officehours.js"} + %script{:src => "static/lib/require.js"} + %script{:src => "static/index.js"} %body .container diff --git a/source/officehours.coffee b/source/officehours.coffee index f774af6..60b9877 100644 --- a/source/officehours.coffee +++ b/source/officehours.coffee @@ -10,13 +10,13 @@ define [ diff = d.getDate() - day + (if day == 0 then -6 else 1) new Date d.setDate diff - class Officehours + class OfficeHours extends Backbone.Model start: null, url: -> - if start isintanceof Date then "/oh/hours/#{urlEncode start}" else "/oh/hours/" + if @start instanceof Date then "/oh/hours/#{encodeURIComponent @start}" else "/oh/hours/" - initialize: + initialize: (model, option) -> @start = monday(new Date) # This is going to go with the Google idea of a view and overlays: @@ -25,22 +25,20 @@ define [ class Appointments extends Backbone.View - class OfficeHours extends Backbone.View + class OfficeHoursView extends Backbone.View class DayView extends Backbone.View class CalendarView extends Backbone.View - className 'calendar' + className: 'calendar' - - events + events: 'click .forward': "nextWeek" 'click .backward': "lastWeek" initialize: (options) -> - -> - officehours = new OfficeHours - $.when(officehours.fetch()).then(console.log(officehours.get('start'))) + officehours = new OfficeHours() + $.when(officehours.fetch()).then(console.log(officehours))