From b7c12f928bd574c5e0cb1ddec4d39549b8b99e06 Mon Sep 17 00:00:00 2001 From: Vit Brunner Date: Mon, 10 Jun 2013 22:24:51 +0100 Subject: [PATCH] Initial project setup Featuring: - middleman setup - dummy controller and index page - markdown reader and its qunit tests - travis integration --- .gitignore | 4 + .travis.yml | 13 +++ Gemfile | 4 + Gemfile.lock | 104 ++++++++++++++++++++ Makefile | 3 + config.rb | 8 ++ package.json | 11 +++ source/_scripts.haml | 8 ++ source/index.haml | 14 +++ source/scripts/app.coffee | 1 + source/scripts/controllers.coffee | 6 ++ source/scripts/reader/markdown.coffee | 45 +++++++++ source/scripts/services.coffee | 0 source/scripts/tests/reader/markdown.coffee | 78 +++++++++++++++ source/styles/style.sass | 2 + source/tests.haml | 14 +++ 16 files changed, 315 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Makefile create mode 100644 config.rb create mode 100644 package.json create mode 100644 source/_scripts.haml create mode 100644 source/index.haml create mode 100644 source/scripts/app.coffee create mode 100644 source/scripts/controllers.coffee create mode 100644 source/scripts/reader/markdown.coffee create mode 100644 source/scripts/services.coffee create mode 100644 source/scripts/tests/reader/markdown.coffee create mode 100644 source/styles/style.sass create mode 100644 source/tests.haml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d744fa1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.sass-cache +/build +/node_modules +/source/data diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9d07857 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: node_js + +node_js: + - 0.10 + +before_script: + - bundle + - npm install + +script: + - middleman & + - sleep 5 + - node_modules/phantomjs/bin/phantomjs node_modules/qunitjs/addons/phantomjs/runner.js http://0.0.0.0:4567/tests.html diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e534c4a --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'http://rubygems.org' + +gem "middleman", "~>3.0.13" +gem 'rb-inotify', '~> 0.9' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d5b1a91 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,104 @@ +GEM + remote: http://rubygems.org/ + specs: + activesupport (3.2.13) + i18n (= 0.6.1) + multi_json (~> 1.0) + chunky_png (1.2.8) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.3.3) + compass (0.12.2) + chunky_png (~> 1.2) + fssm (>= 0.2.7) + sass (~> 3.1) + execjs (1.4.0) + multi_json (~> 1.0) + ffi (1.8.1) + fssm (0.2.10) + haml (4.0.2) + tilt + hike (1.2.2) + http_router (0.10.2) + rack (>= 1.0.0) + url_mount (~> 0.2.1) + i18n (0.6.1) + listen (0.7.3) + maruku (0.6.1) + syntax (>= 1.0.0) + middleman (3.0.13) + middleman-core (= 3.0.13) + middleman-more (= 3.0.13) + middleman-sprockets (~> 3.0.8) + middleman-core (3.0.13) + activesupport (~> 3.2.6) + bundler (~> 1.1) + listen (~> 0.7.3) + rack (~> 1.4.1) + rack-test (~> 0.6.1) + rb-fsevent (~> 0.9.3) + thor (~> 0.15.4) + tilt (~> 1.3.6) + middleman-more (3.0.13) + coffee-script (~> 2.2.0) + coffee-script-source (~> 1.3.3) + compass (>= 0.12.2) + execjs (~> 1.4.0) + haml (>= 3.1.6) + i18n (~> 0.6.0, < 0.6.2) + maruku (~> 0.6.0) + middleman-core (= 3.0.13) + padrino-helpers (= 0.10.7) + sass (>= 3.1.20) + uglifier (~> 1.2.6) + middleman-sprockets (3.0.11) + middleman-more (>= 3.0.11) + sprockets (~> 2.1) + sprockets-sass (~> 0.9.1) + multi_json (1.7.3) + padrino-core (0.10.7) + activesupport (~> 3.2.0) + http_router (~> 0.10.2) + sinatra (~> 1.3.1) + thor (~> 0.15.2) + tilt (~> 1.3.0) + padrino-helpers (0.10.7) + i18n (~> 0.6) + padrino-core (= 0.10.7) + rack (1.4.5) + rack-protection (1.5.0) + rack + rack-test (0.6.2) + rack (>= 1.0) + rb-fsevent (0.9.3) + rb-inotify (0.9.0) + ffi (>= 0.5.0) + sass (3.2.9) + sinatra (1.3.6) + rack (~> 1.4) + rack-protection (~> 1.3) + tilt (~> 1.3, >= 1.3.3) + sprockets (2.9.3) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-sass (0.9.1) + sprockets (~> 2.0) + tilt (~> 1.1) + syntax (1.0.0) + thor (0.15.4) + tilt (1.3.7) + uglifier (1.2.7) + execjs (>= 0.3.0) + multi_json (~> 1.3) + url_mount (0.2.1) + rack + +PLATFORMS + ruby + +DEPENDENCIES + middleman (~> 3.0.13) + rb-inotify (~> 0.9) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a00474f --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +default: + bundle + middleman build diff --git a/config.rb b/config.rb new file mode 100644 index 0000000..10fcb8b --- /dev/null +++ b/config.rb @@ -0,0 +1,8 @@ +set :css_dir, 'styles' +set :js_dir, 'scripts' + +Tilt.mappings.delete('md') + +configure :build do + activate :minify_css +end diff --git a/package.json b/package.json new file mode 100644 index 0000000..a7bff17 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "side-by-side", + "version": "0.0.1", + "author": "Vit Brunner", + "description": "Visual comparison of different translations of itemized texts; e.g. poems, bibles, etc.", + "devDependencies": { + "qunitjs": "1.11.x", + "phantomjs": "1.9.x" + }, + "license": "MIT" +} diff --git a/source/_scripts.haml b/source/_scripts.haml new file mode 100644 index 0000000..0d69070 --- /dev/null +++ b/source/_scripts.haml @@ -0,0 +1,8 @@ +/ application scripts +#{javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.5/angular.js"} +/ TODO use cdnjs.com once they serve marked +#{javascript_include_tag "//raw.github.com/chjj/marked/master/lib/marked.js"} +#{javascript_include_tag "app"} +#{javascript_include_tag "services"} +#{javascript_include_tag "reader/markdown"} +#{javascript_include_tag "controllers"} diff --git a/source/index.haml b/source/index.haml new file mode 100644 index 0000000..b112495 --- /dev/null +++ b/source/index.haml @@ -0,0 +1,14 @@ +!!! 5 +%html{"ng-app" => "sideBySide"} + %head + %title Side By Side viewer + %meta{:charset => "utf-8"} + #{stylesheet_link_tag "//fonts.googleapis.com/css?family=Titillium+Web:400,700,400italic,700italic"} + #{stylesheet_link_tag "style"} + = render_partial 'scripts' + + %body + %div{:class => "container", "ng-controller" => "comparisonController"} + %div{:class => "verse", "ng-repeat" => "verse in verses"} + %div{:class => "section", "ng-bind" => "verse.section"} + %div{:class => "version", "ng-repeat" => "version in verse.versions"} {{ version }} diff --git a/source/scripts/app.coffee b/source/scripts/app.coffee new file mode 100644 index 0000000..f287e3f --- /dev/null +++ b/source/scripts/app.coffee @@ -0,0 +1 @@ +angular.module 'sideBySide', ['sideBySide.controllers'] diff --git a/source/scripts/controllers.coffee b/source/scripts/controllers.coffee new file mode 100644 index 0000000..06d2f34 --- /dev/null +++ b/source/scripts/controllers.coffee @@ -0,0 +1,6 @@ +angular.module("sideBySide.controllers", []) +.controller "comparisonController", ($scope) -> + $scope.verses = [ + { section: 'first', versions: [ 'a', '1' ] } + { section: 'second', versions: [ 'b', '2' ] } + ] diff --git a/source/scripts/reader/markdown.coffee b/source/scripts/reader/markdown.coffee new file mode 100644 index 0000000..4f2a88e --- /dev/null +++ b/source/scripts/reader/markdown.coffee @@ -0,0 +1,45 @@ +angular.module("sideBySide").factory("markdownReader", () -> + return (source) -> + read_meta = (block, inlineLexer) -> + meta = {} + lexed = inlineLexer.output(block.text) + for line in lexed.split("\n") + match = /([^:]*):(.*)/.exec(line) + meta[match[1].trim()] = match[2].trim() + return meta + + read_content = (lexed) -> + get_section = (lexed) -> + items = [] + while lexed.length > 0 + if lexed[0]["type"] == "heading" + break + items.push(lexed.shift()) + return items + + content = [] + + while lexed.length > 0 + if lexed[0]["type"] == "heading" + heading = lexed.shift().text + else + heading = '' + + text = get_section(lexed) + text.links = lexed.links + content.push({ + section: heading + text: marked.parser(text) + }) + + return content + + lexed = marked.lexer(source) + meta = lexed.shift() + inlineLexer = new marked.InlineLexer(lexed.links) + + return { + meta: read_meta(meta, inlineLexer) + content: read_content(lexed) + } +) diff --git a/source/scripts/services.coffee b/source/scripts/services.coffee new file mode 100644 index 0000000..e69de29 diff --git a/source/scripts/tests/reader/markdown.coffee b/source/scripts/tests/reader/markdown.coffee new file mode 100644 index 0000000..866e09d --- /dev/null +++ b/source/scripts/tests/reader/markdown.coffee @@ -0,0 +1,78 @@ +test("markdownReader", () -> + injector = angular.injector(["ng", "sideBySide"]) + markDownReader = injector.get("markdownReader") + + testCases = [{ + tested: """ + Title: Universal Declaration of Human Rights + Author: John Peters Humphrey + Date: 1948 + Source: http://en.wikisource.org/wiki/Universal_Declaration_of_Human_Rights + + ## 1 + All human beings are born *free* and equal in dignity and rights... + + ## 2 + Everyone is entitled to all the rights and freedoms... + + Furthermore, no distinction shall be made on the basis of... + + ## 11.1 + Everyone charged with a penal offence has the right to be presumed... + + ## 11.2 + No one shall be held guilty of any penal offence... + + ## 13 + Everyone is entitled to: + + - sex + - drugs + - rock & roll + """ + expected: { + meta: { + Title: "Universal Declaration of Human Rights" + Author: "John Peters Humphrey" + Date: "1948" + Source: 'http://en.wikisource.org/wiki/Universal_Declaration_of_Human_Rights' + } + content: [ + { section: "1", text: "

All human beings are born free and equal in dignity and rights...

\n" } + { section: "2", text: """

Everyone is entitled to all the rights and freedoms...

+

Furthermore, no distinction shall be made on the basis of...

\n""" } + { section: "11.1", text: "

Everyone charged with a penal offence has the right to be presumed...

\n" } + { section: "11.2", text: "

No one shall be held guilty of any penal offence...

\n" } + { section: "13", text: """

Everyone is entitled to:

+ \n""" } + ] + } + }, { + tested: """ + Title: Test leading text + + **This** is leading text. + # I + First section. + # II + Second section. + """ + expected: { + meta: { + Title: "Test leading text" + } + content: [ + { section: "", text: "

This is leading text.

\n" } + { section: "I", text: "

First section.

\n" } + { section: "II", text: "

Second section.

\n" } + ] + } + }] + + for testCase in testCases + deepEqual(markDownReader(testCase.tested), testCase.expected) +) diff --git a/source/styles/style.sass b/source/styles/style.sass new file mode 100644 index 0000000..1c2183f --- /dev/null +++ b/source/styles/style.sass @@ -0,0 +1,2 @@ +body + font-family: "Titillium Web", sans-serif diff --git a/source/tests.haml b/source/tests.haml new file mode 100644 index 0000000..cc78807 --- /dev/null +++ b/source/tests.haml @@ -0,0 +1,14 @@ +!!! 5 +%html + %head + %title Side By Side test suite + %meta{:charset => "utf-8"} + = render_partial 'scripts' + + / test scripts + #{stylesheet_link_tag "//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.css"} + #{javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.js"} + #{javascript_include_tag "tests/reader/markdown"} + + %body + %div{:id => "qunit"}