@@ -4,10 +4,9 @@ Elm.Native.Text.make = function(elm) {
44 elm.Native.Text = elm.Native.Text || {};
55 if (elm.Native.Text.values) return elm.Native.Text.values;
66
7− var JS = Elm.JavaScript.make(elm);
8− var Utils = Elm.Native.Utils.make(elm);
9− var Color = Elm.Native.Color.make(elm);
107 var Element = Elm.Graphics.Element.make(elm);
8+ var List = Elm.Native.List.make(elm);
9+ var Utils = Elm.Native.Utils.make(elm);
1110 var show = Elm.Native.Show.make(elm).show;
1211
1312 function makeSpaces(s) {
@@ -51,13 +50,58 @@ Elm.Native.Text.make = function(elm) {
5150 return arr.join('<br/>');
5251 }
5352
54− function toText(str) { return Utils.txt(properEscape(JS.fromString(str))); }
53+ function toText(str) { return Utils.txt(properEscape(str)); }
54+
55+ // conversions from Elm values to CSS
56+ function toTypefaces(list) {
57+ var typefaces = List.toArray(list);
58+ for (var i = typefaces.length; i--; ) {
59+ var typeface = typefaces[i];
60+ if (typeface.contains(' ')) {
61+ typefaces[i] = "'" + typeface + "'";
62+ }
63+ }
64+ return typefaces.join(',');
65+ }
66+ function toLine(line) {
67+ var ctor = line.ctor;
68+ var decoration = ctor === 'Under' ? 'underline' :
69+ ctor === 'Over' ? 'overline' : 'line-through';
70+ return 'text-decoration:' + decoration + ';';
71+ }
72+ function toColor(c) {
73+ var color = (c._3 === 1)
74+ ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
75+ : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
76+ return 'color:' + color + ';';
77+ }
5578
79+ // setting styles of Text
80+ function style(style, text) {
81+ var newText = '<span style="' + toColor(style.color);
82+ if (style.typeface.ctor !== '[]') {
83+ newText += 'font-family:' + toTypefaces(style.typeface) + ';'
84+ }
85+ if (style.height.ctor !== "Nothing") {
86+ newText += 'font-size:' + style.height._0 + 'px;';
87+ }
88+ if (style.bold) {
89+ newText += 'font-weight:bold;';
90+ }
91+ if (style.italic) {
92+ newText += 'font-style:italic;';
93+ }
94+ if (style.line.ctor !== 'Nothing') {
95+ newText += toLine(style.line._0);
96+ }
97+ newText += '">' + Utils.makeText(text) + '</span>'
98+ return Utils.txt(newText);
99+ }
56100 function height(px, text) {
57101 return { style: 'font-size:' + px + 'px;', text:text }
58102 }
59− function typeface(name, text) {
60− return { style: 'font-family:' + name + ';', text:text }
103+ function typeface(names, text) {
104+ return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
61105 }
62106 function monospace(text) {
63107 return { style: 'font-family:monospace;', text:text }
@@ -71,14 +115,8 @@ Elm.Native.Text.make = function(elm) {
71115 function link(href, text) {
72116 return { href: toText(href), text:text };
73117 }
74− function underline(text) {
75− return { line: ' underline', text:text };
76− }
77− function overline(text) {
78− return { line: ' overline', text:text };
79− }
80− function strikeThrough(text) {
81− return { line: ' line-through', text:text };
118+ function line(line, text) {
119+ return { style: toLine(line), text:text };
82120 }
83121
84122 function color(c, text) {
@@ -88,8 +126,8 @@ Elm.Native.Text.make = function(elm) {
88126 return { style: 'color:' + color + ';', text:text };
89127 }
90128
91− function position(align) {
92− function create(text) {
129+ function block(align) {
130+ return function(text) {
93131 var raw = {
94132 ctor :'RawHtml',
95133 html : Utils.makeText(text),
@@ -100,7 +138,6 @@ Elm.Native.Text.make = function(elm) {
100138 var pos = A2(Utils.htmlHeight, 0, raw);
101139 return A3(Element.newElement, pos._0, pos._1, raw);
102140 }
103− return create;
104141 }
105142
106143 function markdown(text, guid) {
@@ -115,36 +152,22 @@ Elm.Native.Text.make = function(elm) {
115152 return A3(Element.newElement, pos._0, pos._1, raw);
116153 }
117154
118− var text = position('left');
119− function asText(v) {
120− return text(monospace(toText(show(v))));
121− }
122−
123− function plainText(v) {
124− return text(toText(v));
125− }
126−
127155 return elm.Native.Text.values = {
128156 toText: toText,
129157
130158 height : F2(height),
131159 italic : italic,
132160 bold : bold,
133− underline : underline,
134− overline : overline,
135− strikeThrough : strikeThrough,
161+ line : F2(line),
136162 monospace : monospace,
137163 typeface : F2(typeface),
138164 color : F2(color),
139165 link : F2(link),
140166
141− justified : position('justify'),
142− centered : position('center'),
143− righted : position('right'),
144− text : text,
145− plainText : plainText,
146− markdown : markdown,
147−
148− asText : asText,
167+ leftAligned : block('left'),
168+ rightAligned : block('right'),
169+ centered : block('center'),
170+ justified : block('justify'),
171+ markdown : markdown,
149172 };
150173};