Skip to content

Commit

Permalink
* Deploy the fully server-rendered isomorphic hruby
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyt committed Apr 13, 2015
1 parent e1c1911 commit 496b2e5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion main.ls
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function xref-of (id, src-lang=LANG, tgt-lang-only)
part = words.slice(idx + id.length + 4);
idx = part.indexOf \"
part.=slice 0 idx
[ x || id for x in part / \, ]
[ x || id for x in part / /,+/ ]
return rv[tgt-lang] if tgt-lang-only
return rv

Expand Down
2 changes: 1 addition & 1 deletion manifest.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
# Sun Apr 12 17:13:26 CST 2015
# Mon Apr 13 08:13:26 CST 2015

CACHE:

Expand Down
10 changes: 8 additions & 2 deletions scripts/RightAngle.ls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ React = require \react
createClass = React.createFactory << React.createClass
module.exports = createClass do
render: ->
__html = "<hruby class='rightangle' rightangle>#{ ruby2hruby @props.html }</hruby>"
__html = """
<hruby class="rightangle" rightangle="rightangle">#{
ruby2hruby @props.html
}</hruby>
"""
React.createElement \span dangerouslySetInnerHTML: { __html }

# Algorithm and constants below are derived from
Expand Down Expand Up @@ -111,4 +115,6 @@ ruby2hruby = (html) ->
for x in aRb => $(x).remove!
$('rtc').remove()
$('rt').attr \style 'text-indent: -9999px; color: transparent'
return $('ruby').html()
return $('ruby').html().replace(
/&#x([0-9a-fA-F]+);/g (_, _1) -> String.fromCharCode parseInt(_1, 16)
)
2 changes: 1 addition & 1 deletion server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server.ls
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for let lang in <[ a t h c ]>
function xref-of (id, src-lang)
rv = {}
for tgt-lang, words of XREF[src-lang] | words[id]?
rv[tgt-lang] = [ x || id for x in words[id] / \, ]
rv[tgt-lang] = [ x || id for x in words[id] / /,+/ ]
return rv

trim = -> (it ? '').replace /[`~]/g ''
Expand Down
16 changes: 7 additions & 9 deletions view.ls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require! <[
]>

# Use the ./ prefix only for the web, not Cordova
const DotSlash = if document.URL is /^https?:/ then "./" else ""
const DotSlash = if !(document?) or document?URL is /^https?:/ then "./" else ""

React = require('react')
window.isMoedictDesktop = isMoedictDesktop = true if window?moedictDesktop
Expand Down Expand Up @@ -91,9 +91,8 @@ XRefs = createClass do
div { className: \xrefs }, ...for { lang, words } in xrefs
H = "#DotSlash#{ HASH-OF[lang] }"
div { key: lang, className: \xref-line },
span { className: 'xref part-of-speech' },
span { className: 'xref part-of-speech' style: marginRight: \5px },
XREF-LABEL-OF["#LANG#lang"] || XREF-LABEL-OF[lang]
nbsp
span { className: 'xref', itemProp: \citation },
...intersperse \、, for word in words
word -= /[`~]/g
Expand Down Expand Up @@ -448,9 +447,8 @@ function decorate-nyms (props)
list = []
for key, val of { synonyms: \似, antonyms: \反, variants: \異 } | props[key]
list ++= span { key, className: key },
span { className: \part-of-speech }, val
nbsp
...intersperse \、, for __html in props[key] / \,
span { className: \part-of-speech style: marginRight: \5px }, val
...intersperse \、, for __html in props[key] / /,+/
span { dangerouslySetInnerHTML: { __html } }
return list

Expand Down Expand Up @@ -661,9 +659,9 @@ decodeLangPart = (LANG-OR-H, part='') ->
part.=replace /"`(.)~\u20DE"[^}]*},{"f":"([^(]+)[^"]*"/g '"$1\u20DE $2"'
part.=replace /"([hbpdcnftrelsaqETAVCDS_=])":/g (, k) -> keyMap[k] + \:
H = "#DotSlash#{ HASH-OF[LANG-OR-H] || LANG-OR-H }"
part.=replace /([「【『(《])`([^~]+)~([。,、;:?!─….·-」』》〉]+)/g (, pre, word, post) -> "<span class='punct'>#pre<a href=\\\"#H#word\\\">#word</a>#post</span>"
part.=replace /([「【『(《])`([^~]+)~/g (, pre, word) -> "<span class='punct'>#pre<a href=\\\"#H#word\\\">#word</a></span>"
part.=replace /`([^~]+)~([。,、;:?!─….·-」』》〉]+)/g (, word, post) -> "<span class='punct'><a href=\\\"#H#word\\\">#word</a>#post</span>"
part.=replace /([「【『(《])`([^~]+)~([。,、;:?!─….·-」』》〉]+)/g (, pre, word, post) -> "<span class=\\\"punct\\\">#pre<a href=\\\"#H#word\\\">#word</a>#post</span>"
part.=replace /([「【『(《])`([^~]+)~/g (, pre, word) -> "<span class=\\\"punct\\\">#pre<a href=\\\"#H#word\\\">#word</a></span>"
part.=replace /`([^~]+)~([。,、;:?!─….·-」』》〉]+)/g (, word, post) -> "<span class=\\\"punct\\\"><a href=\\\"#H#word\\\">#word</a>#post</span>"
part.=replace /`([^~]+)~/g (, word) -> "<a href=\\\"#H#word\\\">#word</a>"
part.=replace /([))])/g "$1\u200B"
return part
Expand Down

0 comments on commit 496b2e5

Please sign in to comment.