written 0.0.5 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/LICENSE +8 -0
- data/README.md +63 -0
- data/Rakefile +17 -27
- data/lib/written.rb +0 -8
- data/lib/written/app/assets/images/written/placeholder.png +0 -0
- data/lib/written/app/assets/javascripts/written.coffee +2 -0
- data/lib/written/app/assets/javascripts/written/core/content.coffee +53 -35
- data/lib/written/app/assets/javascripts/written/core/cursor.coffee +33 -12
- data/lib/written/app/assets/javascripts/written/core/document.coffee +16 -11
- data/lib/written/app/assets/javascripts/written/core/extensions/string.coffee +9 -0
- data/lib/written/app/assets/javascripts/written/core/extensions/text.coffee +2 -0
- data/lib/written/app/assets/javascripts/written/core/history.coffee +2 -0
- data/lib/written/app/assets/javascripts/written/core/observer.coffee +6 -2
- data/lib/written/app/assets/javascripts/written/core/stringify.coffee +15 -0
- data/lib/written/app/assets/javascripts/written/parsers/block.coffee +69 -0
- data/lib/written/app/assets/javascripts/written/parsers/block/code.coffee +79 -15
- data/lib/written/app/assets/javascripts/written/parsers/block/heading.coffee +60 -5
- data/lib/written/app/assets/javascripts/written/parsers/block/image.coffee +103 -9
- data/lib/written/app/assets/javascripts/written/parsers/block/olist.coffee +94 -12
- data/lib/written/app/assets/javascripts/written/parsers/block/paragraph.coffee +63 -5
- data/lib/written/app/assets/javascripts/written/parsers/block/quote.coffee +92 -0
- data/lib/written/app/assets/javascripts/written/parsers/block/ulist.coffee +93 -12
- data/lib/written/app/assets/javascripts/written/parsers/inline.coffee +81 -0
- data/lib/written/app/assets/javascripts/written/parsers/inline/code.coffee +57 -0
- data/lib/written/app/assets/javascripts/written/parsers/inline/italic.coffee +40 -7
- data/lib/written/app/assets/javascripts/written/parsers/inline/link.coffee +43 -13
- data/lib/written/app/assets/javascripts/written/parsers/inline/list.coffee +27 -0
- data/lib/written/app/assets/javascripts/written/parsers/inline/strong.coffee +41 -7
- data/lib/written/app/assets/javascripts/written/parsers/parsers.coffee +21 -107
- data/lib/written/app/assets/javascripts/written/polyfills/CustomElements/CustomElements.js +32 -0
- data/lib/written/app/assets/javascripts/written/polyfills/CustomElements/base.js +40 -0
- data/lib/written/app/assets/javascripts/written/polyfills/CustomElements/boot.js +124 -0
- data/lib/written/app/assets/javascripts/written/polyfills/CustomElements/observe.js +318 -0
- data/lib/written/app/assets/javascripts/written/polyfills/CustomElements/register.js +369 -0
- data/lib/written/app/assets/javascripts/written/polyfills/CustomElements/traverse.js +86 -0
- data/lib/written/app/assets/javascripts/written/polyfills/CustomElements/upgrade.js +130 -0
- data/lib/written/app/assets/javascripts/written/polyfills/MutationObserver/MutationObserver.js +575 -0
- data/lib/written/app/assets/javascripts/written/polyfills/WeakMap/WeakMap.js +49 -0
- data/lib/written/app/assets/javascripts/written/polyfills/base.coffee +10 -0
- data/lib/written/app/assets/javascripts/written/polyfills/dom.js +104 -0
- data/lib/written/app/assets/javascripts/written/uploaders/aws.coffee +125 -0
- data/lib/written/app/assets/stylesheets/written.scss +80 -11
- data/lib/written/version.rb +1 -1
- data/test/server/app/assets/javascripts/application.coffee +20 -2
- data/test/server/app/assets/stylesheets/application.scss +2 -2
- data/test/server/app/assets/stylesheets/prism.css +0 -1
- data/test/server/app/views/posts/show.html.erb +10 -3
- metadata +26 -20
- data/lib/written/app/assets/javascripts/written/core/ext.coffee +0 -109
- data/lib/written/app/assets/javascripts/written/core/extensions.coffee +0 -2
- data/lib/written/document.rb +0 -42
- data/lib/written/node.rb +0 -21
- data/lib/written/nodes/code.rb +0 -65
- data/lib/written/nodes/heading.rb +0 -15
- data/lib/written/nodes/image.rb +0 -14
- data/lib/written/nodes/ordered_list.rb +0 -18
- data/lib/written/nodes/unordered_list.rb +0 -19
- data/lib/written/parsers.rb +0 -11
- data/lib/written/parsers/base.rb +0 -26
- data/lib/written/parsers/code.rb +0 -60
- data/lib/written/parsers/heading.rb +0 -19
- data/lib/written/parsers/image.rb +0 -19
- data/lib/written/parsers/link.rb +0 -12
- data/lib/written/parsers/list.rb +0 -33
- data/lib/written/parsers/word.rb +0 -16
data/lib/written/parsers/base.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Written::Parsers
|
2
|
-
class Base
|
3
|
-
class << self
|
4
|
-
private :new
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.parse!(document)
|
8
|
-
i = 0
|
9
|
-
while !document.nodes[i].nil? do
|
10
|
-
node = new(document, document.nodes[i], i).parse!
|
11
|
-
i = document.nodes.index(node) + 1
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(document, node, index)
|
16
|
-
@document = document
|
17
|
-
@node = node
|
18
|
-
@index = index
|
19
|
-
end
|
20
|
-
|
21
|
-
def parse!
|
22
|
-
return @node
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
data/lib/written/parsers/code.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
module Written::Parsers
|
2
|
-
class Code < Base
|
3
|
-
OPENING_TAG = /((~{3,})([a-z]+)?)(.+)?/i
|
4
|
-
attr_accessor :open
|
5
|
-
|
6
|
-
def parse!
|
7
|
-
|
8
|
-
unless @node.instance_of?(Written::Node)
|
9
|
-
return @node
|
10
|
-
end
|
11
|
-
|
12
|
-
while m = OPENING_TAG.match(@node.content)
|
13
|
-
node = Written::Nodes::Code.new(m)
|
14
|
-
@node.content.slice!(m.offset(1)[0], m[1].size)
|
15
|
-
close(node, m[2].size)
|
16
|
-
end
|
17
|
-
|
18
|
-
return @node
|
19
|
-
end
|
20
|
-
|
21
|
-
def close(node, tildeCount)
|
22
|
-
regex = Regexp.new("(~{#{tildeCount},})", Regexp::IGNORECASE)
|
23
|
-
|
24
|
-
if match = regex.match(node.content)
|
25
|
-
@node.content.slice!(node.offset, match.offset(1)[1])
|
26
|
-
node.content.slice!(match.offset(0)[0], node.content.length - match.offset(0)[0])
|
27
|
-
node.content.lstrip!
|
28
|
-
@node.content.insert(node.offset, node.to_s)
|
29
|
-
|
30
|
-
elsif node.offset == 0
|
31
|
-
extract_siblings(node, regex)
|
32
|
-
@node = node
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def extract_siblings(node, regex)
|
37
|
-
i = @index + 1
|
38
|
-
nodes = []
|
39
|
-
node.title = (node.content || "").strip
|
40
|
-
|
41
|
-
while !(n = @document.nodes[i]).nil?
|
42
|
-
match = regex.match(n.content)
|
43
|
-
@document.nodes.delete_at(i)
|
44
|
-
if match.nil?
|
45
|
-
nodes.push n
|
46
|
-
else
|
47
|
-
break
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
node.content = nodes
|
52
|
-
node.block = true
|
53
|
-
|
54
|
-
@document.nodes[@index] = node
|
55
|
-
|
56
|
-
return node
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Written::Parsers
|
2
|
-
class Heading < Base
|
3
|
-
RULE = /^(\#{1,6} )(.+)/i
|
4
|
-
|
5
|
-
def parse!
|
6
|
-
|
7
|
-
unless @node.instance_of?(Written::Node)
|
8
|
-
return @node
|
9
|
-
end
|
10
|
-
|
11
|
-
if match = RULE.match(@node.content)
|
12
|
-
size = match[1].length - 1
|
13
|
-
@node = Written::Nodes::Heading.new(size, match[2])
|
14
|
-
@document.nodes[@index] = @node
|
15
|
-
end
|
16
|
-
return @node
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Written::Parsers
|
2
|
-
class Image < Base
|
3
|
-
RULE = /^(!{1}\[([^\]]+)\])(\(([^\s]+)?\))$/i
|
4
|
-
|
5
|
-
def parse!
|
6
|
-
|
7
|
-
unless @node.instance_of?(Written::Node)
|
8
|
-
return @node
|
9
|
-
end
|
10
|
-
|
11
|
-
if match = RULE.match(@node.content)
|
12
|
-
@node = Written::Nodes::Image.new(match[2], match[4])
|
13
|
-
@document.nodes[@index] = @node
|
14
|
-
end
|
15
|
-
return @node
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
data/lib/written/parsers/link.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module Written::Parsers
|
2
|
-
class Link < Base
|
3
|
-
RULE = /!{0}(\[([^\]]+)\])(\(([^\)]+)\))/i
|
4
|
-
|
5
|
-
def parse!
|
6
|
-
while match = RULE.match(@node.content) do
|
7
|
-
@node.content.gsub! match[0], "<a href='#{match[4]}'>#{match[2]}</a>"
|
8
|
-
end
|
9
|
-
return @node
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/lib/written/parsers/list.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module Written::Parsers
|
2
|
-
class List < Base
|
3
|
-
UL = /^(-\s)(.+)?$/i
|
4
|
-
OL = /^(\d+\.\s)(.+)?$/i
|
5
|
-
|
6
|
-
def parse!
|
7
|
-
|
8
|
-
unless @node.instance_of?(Written::Node)
|
9
|
-
return @node
|
10
|
-
end
|
11
|
-
|
12
|
-
if match = UL.match(@node.content)
|
13
|
-
list! match, Written::Nodes::UnorderedList
|
14
|
-
elsif match = OL.match(@node.content)
|
15
|
-
list! match, Written::Nodes::OrderedList
|
16
|
-
end
|
17
|
-
return @node
|
18
|
-
end
|
19
|
-
|
20
|
-
def list!(match, tag)
|
21
|
-
previous_node = @document.nodes[@index - 1]
|
22
|
-
if previous_node.nil? || !previous_node.instance_of?(tag)
|
23
|
-
@node = tag.new(match[2])
|
24
|
-
@document.nodes[@index] = @node
|
25
|
-
else
|
26
|
-
@index -= 1
|
27
|
-
@document.nodes.delete(@node)
|
28
|
-
previous_node.append(match[2])
|
29
|
-
@node = previous_node
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/written/parsers/word.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Written::Parsers
|
2
|
-
class Word < Base
|
3
|
-
RULE = /((\*{1,2})([^\*]+)(\*{1,2}))/i
|
4
|
-
|
5
|
-
def parse!
|
6
|
-
while match = RULE.match(@node.content) do
|
7
|
-
if match[2].length == 1
|
8
|
-
@node.content.gsub! match[0], "<em>#{match[3]}</em>"
|
9
|
-
elsif match[2].length == 2
|
10
|
-
@node.content.gsub! match[0], "<strong>#{match[3]}</strong>"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
return @node
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|