Commits

Anonymous committed e37fa6f Draft

.

Comments (0)

Files changed (4)

js/format/sembook.js

         str = str.replace(Node.indent_regex, "");
 
         // Split
-        var split = str.split(TOKENS.DATA);
+        var i = str.indexOf(TOKENS.DATA);
 
         // Invalid
-        if (split.length < 1) {
+        if (str.length < 1) {
             return null;
         }
 
         // Return
-        var tag = split[0];
-        var data = split.length > 1 ? this.unescape_data(split[1]) : null;
-        return (new Node(tag, data));
+        if (i === -1) {
+            // No data
+            return (new Node(str, null));
+        } else {
+            // Data is specified
+            return (new Node(
+                    str.substr(0, i),
+                    this.unescape_data(str.substr(i+1))));
+        }
     };
     
     // 2x escaped version of \n

js/style/asset.js

 define([], function () {
     var exports = {};
 
-    exports.generate_html = function (asset_info, context) {
+    exports.generate_attrs = function (asset_info, info) {
+        var style_obj = {
+            background: 'url('+asset_info.url+') no-repeat',
+            width: info.crop.width,
+            height: info.crop.height,
+            background_size: info.scale.width + "px  " + info.scale.height + "px",
+        };
+
+        if (info.crop.left > 0 || info.crop.top > 0) {
+            style_obj.background_position = '-' + info.crop.left + 'px ' + '-' + info.crop.top + 'px';
+        }
+
+        var s = ''; 
+        for (var k in style_obj) {
+            var v = style_obj[k];
+            s += [k.replace('_', '-'), ": ", v, ";"].join("");
+        }
+        return "style='"+s+"'";
+    };
+
+    exports.generate_html = function (asset_info) {
         // Preview
-        var processing_css = {};
+        var attrs = '';
 
         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);
+            attrs = exports.generate_attrs(asset_info, processing_info);
         }
-
-        var $d = $('<div />')
-                    .css(_.update({
-                            background_image: asset_info.url, 
-                        }, processing_css));
-        return $('<div>').html($d).html();
+        return '<div %s ></div>'.replace("%s", attrs);
     };
 
-    exports.generate_html = function (asset_info, context) {
+    exports.generate_page_html = function (asset_info) {
+        var BODY_STYLE = 'margin: 0; padding: 0';
+        var html = exports.generate_html(asset_info);
+        return [
+                "<html><body style='",  BODY_STYLE, "'>",
+                html,
+                "</body></html>"].join("\n");
+    };
     /*
-    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
         var in_path = path.join(path.dirname(sembook_path), filename);
 
         var asset_info = {
-            path: asset.$('path'),
-            asset_processing: asset.$('asset_processing'),
+            path: asset.$('path').data(),
+            asset_processing: asset.$('asset_processing').data(),
             url:  'file://' + in_path,
-            asset_type: asset.$('asset_type')
+            asset_type: asset.$('asset_type').data()
         };
 
         // Simple template

testdata/test_sembook/test_sembook.sembook

 			assetid:0
 			path:le_cat.jpg
 			asset_type:image
-			asset_processing:{}
+			asset_processing:{"crop": {"height": 701, "width": 433, "top": 0, "left": 0}, "scale": {"height": 701, "width": 433}}
 		asset
 			assetid:1
 			path:tony_trestings.jpg
 			asset_type:image
-			asset_processing:{}
+			asset_processing:{"crop": {"width": 400, "height": 400, "top": 0, "left": 0}, "scale": {"width": 400, "height": 400}}
 	document
 		chapter
 			chapter_title