written 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +128 -0
  5. data/Rakefile +83 -0
  6. data/lib/written/app/assets/javascripts/vendors/prism.js +1411 -0
  7. data/lib/written/app/assets/javascripts/written/core/content.coffee +106 -0
  8. data/lib/written/app/assets/javascripts/written/core/cursor.coffee +59 -0
  9. data/lib/written/app/assets/javascripts/written/core/document.coffee +19 -0
  10. data/lib/written/app/assets/javascripts/written/core/ext.coffee +109 -0
  11. data/lib/written/app/assets/javascripts/written/core/extensions.coffee +2 -0
  12. data/lib/written/app/assets/javascripts/written/core/history.coffee +16 -0
  13. data/lib/written/app/assets/javascripts/written/core/observer.coffee +29 -0
  14. data/lib/written/app/assets/javascripts/written/extensions/clipboard.coffee +114 -0
  15. data/lib/written/app/assets/javascripts/written/extensions/image.coffee +91 -0
  16. data/lib/written/app/assets/javascripts/written/parsers/block/code.coffee +25 -0
  17. data/lib/written/app/assets/javascripts/written/parsers/block/heading.coffee +10 -0
  18. data/lib/written/app/assets/javascripts/written/parsers/block/image.coffee +18 -0
  19. data/lib/written/app/assets/javascripts/written/parsers/block/olist.coffee +18 -0
  20. data/lib/written/app/assets/javascripts/written/parsers/block/paragraph.coffee +10 -0
  21. data/lib/written/app/assets/javascripts/written/parsers/block/ulist.coffee +17 -0
  22. data/lib/written/app/assets/javascripts/written/parsers/inline/italic.coffee +13 -0
  23. data/lib/written/app/assets/javascripts/written/parsers/inline/link.coffee +16 -0
  24. data/lib/written/app/assets/javascripts/written/parsers/inline/strong.coffee +12 -0
  25. data/lib/written/app/assets/javascripts/written/parsers/parsers.coffee +98 -0
  26. data/lib/written/app/assets/javascripts/written.coffee +4 -0
  27. data/lib/written/app/assets/stylesheets/vendors/prism.css +138 -0
  28. data/lib/written/app/assets/stylesheets/written.scss +21 -0
  29. data/lib/written/document.rb +42 -0
  30. data/lib/written/node.rb +21 -0
  31. data/lib/written/nodes/code.rb +65 -0
  32. data/lib/written/nodes/heading.rb +15 -0
  33. data/lib/written/nodes/image.rb +14 -0
  34. data/lib/written/nodes/ordered_list.rb +18 -0
  35. data/lib/written/nodes/unordered_list.rb +19 -0
  36. data/lib/written/parsers/base.rb +26 -0
  37. data/lib/written/parsers/code.rb +60 -0
  38. data/lib/written/parsers/heading.rb +19 -0
  39. data/lib/written/parsers/image.rb +19 -0
  40. data/lib/written/parsers/link.rb +12 -0
  41. data/lib/written/parsers/list.rb +33 -0
  42. data/lib/written/parsers/word.rb +16 -0
  43. data/lib/written/parsers.rb +11 -0
  44. data/lib/written/railtie.rb +20 -0
  45. data/lib/written/version.rb +3 -0
  46. data/lib/written.rb +14 -0
  47. data/test/javascript/assertions/assert.coffee +3 -0
  48. data/test/javascript/polyfills/HTMLULListElement.coffee +0 -0
  49. data/test/javascript/polyfills/Text.coffee +0 -0
  50. data/test/javascript/polyfills.coffee +2 -0
  51. data/test/javascript/runner.coffee +46 -0
  52. data/test/javascript/tests/initialization.coffee +16 -0
  53. data/test/javascript/tests/parsing.coffee +9 -0
  54. data/test/ruby/blank_test.rb +83 -0
  55. data/test/server/app/assets/javascripts/application.coffee +3 -0
  56. data/test/server/app/assets/stylesheets/application.scss +10 -0
  57. data/test/server/app/controllers/application_controller.rb +2 -0
  58. data/test/server/app/controllers/posts_controller.rb +4 -0
  59. data/test/server/app/views/layouts/application.html.erb +14 -0
  60. data/test/server/app/views/posts/show.html.erb +14 -0
  61. data/test/server/application.rb +12 -0
  62. data/test/server/config.ru +5 -0
  63. data/test/server/log/test.log +570 -0
  64. data/written.gemspec +17 -0
  65. metadata +106 -0
@@ -0,0 +1,20 @@
1
+ module Written
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'written.assets' do |app|
4
+ app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
5
+ end
6
+
7
+ def paths
8
+ @paths ||= begin
9
+ paths = Rails::Paths::Root.new(root)
10
+ paths.add 'app/assets', glob: '*'
11
+ paths
12
+ end
13
+ end
14
+
15
+ def root
16
+ File.dirname(__FILE__)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Written
2
+ VERSION = '0.0.2'
3
+ end
data/lib/written.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Written
2
+ autoload :Document, 'written/document'
3
+ autoload :Version, 'written/version'
4
+
5
+ def self.parse(str)
6
+ document = Document.new(str)
7
+ document.parse!
8
+ document
9
+ end
10
+ end
11
+
12
+ if defined?(Rails)
13
+ require 'written/railtie'
14
+ end
@@ -0,0 +1,3 @@
1
+ Test.assertions.register 'assert', (result, message = "No message given") ->
2
+ if result != true
3
+ throw new AssertionException(message)
File without changes
@@ -0,0 +1,2 @@
1
+ #= require_self
2
+ #= require_tree ./polyfills
@@ -0,0 +1,46 @@
1
+ system = require('system')
2
+
3
+ class Runner
4
+ tests: ->
5
+ @page.evaluate ->
6
+ Test.retrieveAll()
7
+
8
+ start: =>
9
+ success = 0
10
+ failure = 0
11
+ error = 0
12
+ console.log("\n# Running:\n")
13
+ for suite in @tests()
14
+ console.log "#{suite.name}:"
15
+ for test in suite.tests
16
+ info = @page.evaluate @invoke, suite.name, test
17
+ if info.result == 'success'
18
+ success += 1
19
+ console.log("✓ #{test}")
20
+ else
21
+ failure += 1
22
+ console.log("✖ #{test}")
23
+ console.log(" #{info.message}")
24
+ total = success + failure + error
25
+ console.log "\n#{total} runs, #{success} successful, #{failure} failure and #{error} errors"
26
+
27
+ invoke: (suite, test) ->
28
+ Test.invoke(suite, test)
29
+
30
+ returnValue = -1
31
+ try
32
+ runner = new Runner()
33
+ runner.page = require('webpage').create()
34
+ runner.page.content = '<body><div id="Editor"></div></body>'
35
+ runner.page.onConsoleMessage = (msg) ->
36
+ console.log(msg)
37
+
38
+ if runner.page.injectJs(system.args[1])
39
+ runner.start()
40
+
41
+ returnValue = 0
42
+ catch e
43
+ console.log e
44
+ console.log e.stack
45
+ finally
46
+ phantom.exit(returnValue)
@@ -0,0 +1,16 @@
1
+ subject = new Test.Subject('initialization')
2
+
3
+ subject.test "editor is bound to the element", (test) ->
4
+ el = document.querySelector('#Editor')
5
+ blank = new Blank(el)
6
+ test.assert blank.element() == el, "No element was set"
7
+
8
+ subject.test "editor should be loaded", (test) ->
9
+ el = document.querySelector('#Editor')
10
+ blank = new Blank(el)
11
+ test.assert blank.element().dataset.status == 'loaded', JSON.stringify(blank.element().dataset)
12
+
13
+ subject.test 'editor should load with default parser', (test) ->
14
+ el = document.querySelector('#Editor')
15
+ blank = new Blank(el)
16
+ test.assert blank.parsers.length == Blank.Parsers().sort().length
@@ -0,0 +1,9 @@
1
+ subject = new Test.Subject('parsing')
2
+
3
+ subject.test 'parsing', (test) ->
4
+ el = document.querySelector('#Editor')
5
+ new Blank(el)
6
+ el.innerHTML = '# Hello World!'
7
+ console.log(el.innerHTML)
8
+
9
+
@@ -0,0 +1,83 @@
1
+ require 'blank'
2
+
3
+ require 'minitest/autorun'
4
+
5
+ class MarkdownTest < Minitest::Test
6
+
7
+ def test_paragraph
8
+ document = Blank.parse("Hello world!\nThis is nice.")
9
+ assert_equal '<p>Hello world!</p><p>This is nice.</p>', document.to_html
10
+ end
11
+
12
+ def test_header
13
+ document = Blank.parse('# test')
14
+ assert_equal "<h1>test</h1>", document.to_html
15
+
16
+ document = Blank.parse('## test and *some*')
17
+ assert_equal "<h2>test and <em>some</em></h2>", document.to_html
18
+ end
19
+
20
+ def test_italic
21
+ document = Blank.parse('*test*')
22
+ assert_equal "<p><em>test</em></p>", document.to_html
23
+ end
24
+
25
+ def test_bold
26
+ document = Blank.parse('**test**')
27
+ assert_equal "<p><strong>test</strong></p>", document.to_html
28
+ end
29
+
30
+ def test_bold_and_italic
31
+ document = Blank.parse('***bold and italic***')
32
+ assert_equal "<p><em><strong>bold and italic</strong></em></p>", document.to_html
33
+
34
+ document = Blank.parse('**bold** and *italic*')
35
+ assert_equal "<p><strong>bold</strong> and <em>italic</em></p>", document.to_html
36
+ end
37
+
38
+ def test_code_inline
39
+ document = Blank.parse("This is a ~~~ruby inline code~~~ snippet")
40
+ assert_equal "<p>This is a <code class='language-ruby'>inline code</code> snippet</p>", document.to_html
41
+
42
+ document = Blank.parse("This is a ~~~ruby inline code~~~ snippet. Multiple ~~~ruby instance~~~ can coexist on the same line")
43
+ assert_equal "<p>This is a <code class='language-ruby'>inline code</code> snippet. Multiple <code class='language-ruby'>instance</code> can coexist on the same line</p>", document.to_html
44
+ end
45
+
46
+ def test_code_blocks
47
+ document = Blank.parse("~~~ruby\n# A comment\nRails.application\n~~~")
48
+ assert_equal "<pre><header></header><code class='language-ruby'># A comment\nRails.application</code></pre>", document.to_html
49
+
50
+ document = Blank.parse("~~~ruby a title\n# A comment\nRails.application\n~~~")
51
+ assert_equal "<pre><header>a title</header><code class='language-ruby'># A comment\nRails.application</code></pre>", document.to_html
52
+ end
53
+
54
+ def test_unordered_list
55
+ document = Blank.parse("- ruby\n- Go")
56
+ assert_equal '<ul><li>ruby</li><li>Go</li></ul>', document.to_html
57
+ end
58
+
59
+ def test_ordered_list
60
+ document = Blank.parse("1. Ruby\n2. **Go**")
61
+ assert_equal '<ol><li>Ruby</li><li><strong>Go</strong></li></ol>', document.to_html
62
+ end
63
+
64
+ def test_lists
65
+ document = Blank.parse("1. Ruby\n2. **Go**\n- Test\n- 123")
66
+ assert_equal '<ol><li>Ruby</li><li><strong>Go</strong></li></ol><ul><li>Test</li><li>123</li></ul>', document.to_html
67
+ end
68
+
69
+ def test_lists_with_links
70
+ document = Blank.parse("1. [Ruby](http://ruby.com)\n")
71
+ assert_equal "<ol><li><a href='http://ruby.com'>Ruby</a></li></ol>", document.to_html
72
+ end
73
+
74
+ def test_image
75
+ document = Blank.parse('![An Image](http://bla.com)')
76
+ assert_equal "<figure><img src='http://bla.com' /><figcaption>An Image</figcaption></figure>", document.to_html
77
+ end
78
+
79
+ def test_link
80
+ document = Blank.parse('[A link](http://bla.com)')
81
+ assert_equal "<p><a href='http://bla.com'>A link</a></p>", document.to_html
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ #= require 'written'
2
+
3
+ new Written(document.getElementById('Editor'))
@@ -0,0 +1,10 @@
1
+ @import 'written';
2
+
3
+ #Editor {
4
+ display: block;
5
+ min-height: 450px;
6
+ border: 1px solid gray;
7
+ outline: none;
8
+
9
+ padding: 1em;
10
+ }
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class PostsController < ApplicationController
2
+ def show
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Written Editor Test Application</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= csrf_meta_tags %>
7
+ </head>
8
+
9
+ <body>
10
+ <%= yield %>
11
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
12
+ </body>
13
+ </html>
14
+
@@ -0,0 +1,14 @@
1
+ <h1>Editor tests</h1>
2
+ <div id='Editor' contenteditable=true># Hello World!
3
+ 1. this is a list
4
+ - this is **a** list
5
+ 3. this is [a](http://google.com) *list*. It's special, isn't **it**?
6
+ test *boo* and them *some* or **some!!** a
7
+
8
+
9
+ ![an](image)
10
+
11
+ ~~~javascript
12
+ var test = "hello"
13
+ ~~~
14
+ </div>
@@ -0,0 +1,12 @@
1
+ module WrittenDevApplication
2
+ class Application < Rails::Application
3
+ config.eager_load = false
4
+ secrets.secret_key_base = "Something not so secret :)"
5
+ #config.logger = ActiveSupport::Logger.new('/dev/null')
6
+ config.assets.debug = true
7
+
8
+ if Rails.env.test?
9
+ paths['app/assets'] << '../browser'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ run WrittenDevApplication::Application.initialize!
2
+
3
+ WrittenDevApplication::Application.routes.draw do
4
+ root 'posts#show'
5
+ end