Commits

Anonymous committed 0df3eb0 Draft

.

Comments (0)

Files changed (4)

js/style/asset.js

 define([], function () {
     var exports = {};
 
-    // 
+    exports.generate_html = function (asset_info, context) {
+        // Preview
+        var processing_css = {};
 
-    exports.generate_html = function (asset_info, context, classes) {
-        var processing_info = {};
-        if (asset_info.asset_processing && asset_info.asset_processing.indexOf('{')===0) {
-            processing_info = JSON.parse(asset_info.asset_processing);
+        if (asset_info.asset_processing
+                        && asset_info.asset_processing.indexOf
+                        && asset_info.asset_processing.indexOf('{')===0) {
+            var processing_info = JSON.parse(asset_info.asset_processing);
+            processing_css = exports.generate_processing_css(processing_info);
         }
-        var $i = $('<img />')
-                    .addClass(classes)
-                    .attr("src", asset_info.url);
+
         var $d = $('<div />')
-                    .addClass(classes || 'nonsem preview-image')
-                    .css({
-                        background_image: asset_info.url, 
-                    });
-        return $('<div>'.html($d).html();
+                    .css(_.update({
+                            background_image: asset_info.url, 
+                        }, processing_css));
+        return $('<div>').html($d).html();
     };
 
+    exports.generate_html = function (asset_info, context) {
+    /*
+    var BODY_STYLE = 'margin: 0; padding: 0';
+    var TEMPLATE = [
+                "<html><body style='",  BODY_STYLE, "'>",
+                "<img src='%(url)s' style='", IMG_STYLE, "' >",
+                "</body></html>"]
+
+    exports.render_html = function (asset_info, context, classes) {
+        // Renderable HTML
+    */
+
     return exports;
 });
 

node/nodepackage.js

+/*
+ * Bootstraps client-side JS into node.
+ */
+
 var requirejs = require('./r.js');
 var path = require('path');
 
 // Expose everything (.) (.)
 exports.format = requirejs('format/sembook');
 exports.style = requirejs('style/style');
+exports.style.asset = requirejs('style/asset');
 exports.style.StyleList = requirejs('style/stylelist');
 exports.spec = requirejs('format/spec');
 exports.converter = requirejs('format/converter');
     var result = style.render(sb, opts.render_options, style_options);
     callback(result);
     //return result;
+
+    return
 };
 
 
             asset            is the sembook node of the asset
             browser_target   is the path to the browser HTML file.
         */
+        /*
+            path: file_name,
+            asset_processing: '',
+            asset_type: 'image',
+        */
 
-        // XXX XXX XXX XXX
-        // TODO finish this function, presently in pseudocode:
-        assets_dir = path.dirname(browser_target);
+        var assets_dir = path.join(path.dirname(browser_target), ASSETS);
+        var filename = asset.$('path').data();
+        var out_path = path.join(assets_dir, filename);
+        var in_path = path.join(path.dirname(sembook_path), filename);
 
-        filename = asset.$('filename').data;
+        var asset_info = {
+            path: asset.$('path'),
+            asset_processing: asset.$('asset_processing'),
+            url:  'file://' + in_path,
+            asset_type: asset.$('asset_type')
+        };
 
-        out_path = assets_dir.join(filename);
-
-        // Uses just a hardcoded string SWIG template, something like
-        // <img style="{{ style }}" src="{{ src }}"  /> or whatever.
-        html = sembook_style_module.asset_renderer(asset);
+        // Simple template
+        var html = spackage.style.asset.generate_html(asset_info);
 
         // now actually render it
-        exports.render_html_as_image(html, target, out_path, callback);
+        exports.render_html_as_image(html, out_path, {}, callback);
 
     };
     var COVER_OPTIONS = {
 
     var do_it = function (the_style_list) {
         style_list = the_style_list;
-        //render_browser_html();
-        // XXX XXX XXX XXX
+        // XXX
         // TODO loops through all assets rendering them, and at the end renders
         // cover which in turn renders browser html
-        render_assets();
 
-        // small todo: do render_browser_html at the same time as render_assets,
-        // since the only requirement is that render_assets -> render_cover is
-        // completed before rendering the ebooks
-        // render_assets();
+        // do render_browser_html at the same time as render_assets, since the
+        // only dependency requirement is the following sequence:
+        // render_assets -> render_cover -> any ebook
+        // (browser target, individual assets, and each ebook target can be
+        // done simultaneously)
+        var browser_target = render_browser_html();
+
+        render_assets(browser_target, function () {
+            render_cover();
+        });
     };
 
-    var render_assets = function () {
+    var render_assets = function (browser_target, callback) {
         // Loop through all assets and render them
+        var done = function () {
+            _v('-- Done with asset --');
+            callback();
+        };
+
+        var all_assets = sb.root.filter_children('assets');
+        var assets = all_assets.length > 0 && all_assets[0].filter_children('asset');
+        if (assets && assets.length > 0) {
+            // Do the callback after all the assets have finished rendering
+            var after = _.after(assets.length, done);
+            var i = 0;
+            while (i < assets.length) {
+                var asset = assets[i];
+                render_asset(asset, browser_target, after);
+                i++;
+            }
+        } else  {
+            // No assets??
+            console.error("Likely error: no assets specified.");
+            done();
+        }
     };
 
     var render_browser_html = function () {
                 },
                 function (html_result) {
                     _write(output_paths.html, html_result);
-                    render_cover(); //small todo: comment htis out
+                    //render_cover(); //small todo: comment htis out
                 });
+        return output_paths.html;
     };
 
     var render_cover = function () {

testdata/test_sembook/test_sembook.sembook

 			date
 			edition:1
 	assets
+		asset
+			assetid:0
+			path:le_cat.jpg
+			asset_type:image
+			asset_processing:{}
+		asset
+			assetid:1
+			path:tony_trestings.jpg
+			asset_type:image
+			asset_processing:{}
 	document
 		chapter
 			chapter_title