aboutsummaryrefslogtreecommitdiffstats
path: root/docs/spec/writerSpec.js
blob: 973bb64e050b39ab9ed5034e464726580d4e7dbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var writer = require('writer.js');
describe('writer', function() {
  describe('toString', function() {
    var toString = writer.toString;

    it('should merge string', function() {
      expect(toString('abc')).toEqual('abc');
    });

    it('should merge obj', function() {
      expect(toString({a:1})).toEqual('{"a":1}');
    });

    it('should merge array', function() {
      expect(toString(['abc',{}])).toEqual('abc{}');
    });
  });

  describe('replace method', function() {
    var content,
        replacements;

    beforeEach(function() {
      content = 'angular super jQuery manifest';
    });

    it('should replace placeholders', function() {
      replacements = {'angular': 'ng', 'jQuery': 'jqlite','notHere': 'here'};

      content = writer.replace(content, replacements);
      expect(content).toBe('ng super jqlite manifest');
    });
  });
});
n class="nx">angular.widget('doc:example', function(element){ this.descend(true); //compile the example code element.hide(); var example = element.find('pre.doc-source').eq(0), exampleSrc = example.text(), scenario = element.find('pre.doc-scenario').eq(0); var code = indent(exampleSrc); var tabHtml = '<ul class="doc-example">' + '<li class="doc-example-heading"><h3>Source</h3></li>' + '<li class="doc-example-source" ng:non-bindable>' + '<pre class="brush: js; html-script: true; highlight: [' + code.hilite + ']; toolbar: false;"></pre></li>' + '<li class="doc-example-heading"><h3>Live Preview</h3></li>' + '<li class="doc-example-live">' + exampleSrc +'</li>'; if (scenario.text()) { tabHtml += '<li class="doc-example-heading"><h3>Scenario Test</h3></li>' + '<li class="doc-example-scenario"><pre class="brush: js">' + scenario.text() + '</pre></li>'; } tabHtml += '</ul>'; var tabs = angular.element(tabHtml); tabs.find('li.doc-example-source > pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html)); element.html(''); element.append(tabs); element.show(); var script = (exampleSrc.match(/<script[^\>]*>([\s\S]*)<\/script>/) || [])[1] || ''; try { eval(script); } catch (e) { alert(e); } }); function indent(text) { if (!text) return text; var lines = text.split(/\r?\n/); var lineNo = []; // remove any leading blank lines while (lines[0].match(/^\s*$/)) lines.shift(); // remove any trailing blank lines while (lines[lines.length - 1].match(/^\s*$/)) lines.pop(); var minIndent = 999; for ( var i = 0; i < lines.length; i++) { var line = lines[0]; var indent = line.match(/^\s*/)[0]; if (indent !== line && indent.length < minIndent) { minIndent = indent.length; } } for ( var i = 0; i < lines.length; i++) { lines[i] = ' ' + lines[i].substring(minIndent); lineNo.push(5 + i); } return {html: lines.join('\n'), hilite: lineNo.join(',') }; }; })();