Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

One can know display the associated with a crumb

Used live() to bind the event handler because the code to
be highlighted is dynamically inserted unlike early attempts

Editing is possible but webkit acts weird. One need to move the cursor
to get the boundary displayed.

Also added rule for npm driven global install.
  • Loading branch information...
commit d1e9fd5abc38fd429f3cecba5c816c6db31a3c8b 1 parent 93ae614
Stéphane Payrard authored
2  META.info
View
@@ -1,6 +1,6 @@
{
"name" : "parse-tree-server",
- "version" : "0.0.6",
+ "version" : "0.0.7",
"description" : "parse tree server",
"depends" : ["JSON::Tiny"],
"source-url" : "http://github.com/cognominal/codeview"
4 Makefile
View
@@ -4,6 +4,10 @@ all:
docdown --markdown README.md
npm install .
+# what about the Perl part?
+install:
+ npm install -g .
+
clean:
# remove generated file that are part of the depot
2  i.html
View
@@ -11,7 +11,7 @@
<div id="current-rule"></div>
<div id="parse-crumbs"></div>
<div style="display:none;">breadcrumbs: rule stack from top to reduce current selection</div>
- <pre class="code-top"/>
+ <pre class="code-top"></pre>
</body>
</html>
2  package.json
View
@@ -2,7 +2,7 @@
"name": "parse-tree-server",
"description": "parse tree server",
"keywords": ["web", "server", "syntax", "highlighter"],
- "version": "0.0.6",
+ "version": "0.0.7",
"author": "Stéphane Payrard <cognominal@gmail.com>",
"engines": { "node": ">=0.1.99" },
"bin": { "hilite-server": "./bin/hilite-server" },
35 src/hilite.coffee
View
@@ -1,3 +1,5 @@
+# really need to refactor to emphasize the logic, not the jquery operations
+
$ ->
bread_crumbs_on_hover = 1 # 0 after first click on code/doc
@@ -12,7 +14,7 @@ $ ->
hilite ev
)
- $(".code").bind('vclick',
+ $(".code").live('vclick',
(ev) ->
bread_crumbs_on_hover = 0
ev.stopPropagation()
@@ -22,29 +24,33 @@ $ ->
hilite ev
)
-# .live('mouseover') is necessary because .hover(...) works only
-# on element already existing when creating the handler
$(".parse-subcrumb").live('vmouseover', (ev) ->
+ $(".code").removeClass "editing"
+ bread_crumbs_on_hove = 0
$(".code").removeClass "colored"
$(".parse-subcrumb").removeClass "colored"
- id = ev.currentTarget.id
- $( '#' + id ).addClass "colored" # color the subcrumb
+ elt = ev.currentTarget
+ id = elt.id
+ $(elt).addClass "colored" # color the subcrumb
+ console.log "#{ id.substring 5} #{id}"
+ showRule $(elt).text()
$( '#' + id.substring 5 ).addClass "colored" # color the corresponding code
)
# need to support keymaps
- $(".code").live('vclick',
+ $(".code").live('keydown',
(ev) ->
# console.log ev
ev.stopPropagation()
if ev.keyCode== 27 # escape enlarges the editing zone to the enclosing rule
t = ev.currentTarget
dadInCode = ($(".editing").parent().filter(".code"))[0];
+ console.log dadInCode
if dadInCode?
$(".parse-subcrumb").removeClass "colored"
$(".code").removeClass "editing"
$(dadInCode).addClass "editing"
- $( "#crumb#{dadIncode.id}" ).addClass "colored"
+ $( "#crumb#{dadInCode.id}" ).addClass "colored"
# if t.hasClass "cle-doc"
# t.html t.attr("src").escapeHTML # good as a start but wrong. wipe out structure
if ev.keyCode = 13 && ev.shiftKey
@@ -73,8 +79,13 @@ $ ->
# extract the current rule to add it to the rule vieport
ruleElt = $('#current-rule')
elt = elt.parentNode
- if (rule = ruleNm elt) and (rulesStr = ruleElt.attr('data'))
- ruleElt.text ((JSON.parse rulesStr)[rule])
+ showRule rule if rule = ruleNm elt
+
+
+ showRule = (ruleNm) ->
+ ruleElt = $('#current-rule')
+ rules = JSON.parse ruleElt.attr('data')
+ ruleElt.text rules[ruleNm] if rules[ruleNm]
# A breadcrumb displays the reduction sequence from the parse top. Making a
@@ -126,7 +137,6 @@ $ ->
elt.append '<span>'
e = $ elt[0].lastChild
e.text s if s
-# console.log "=#{klass}"
e.addClass 'docco-' + d if klass and d = docco[klass];
e.addClass 'rule-' + klass if klass
e.addClass 'code' # is that necessary except for the englobing element?
@@ -136,11 +146,10 @@ $ ->
for k, v of parseTree
elt = appendElt elt, null, k
for m in v
-# console.log "'#{m}' #{$.type m}"
if $.type(m) == "string"
appendElt elt, m
else
- insertParseTree elt, m, id++
+ insertParseTree elt, m, id
generateView = (elt, data, id=0, prefix='') ->
@@ -149,6 +158,4 @@ $ ->
$.getJSON 'data/parsed.json', (data) ->
-# console.log data
-# console.log $.type data
generateView $('.code-top'), data
Please sign in to comment.
Something went wrong with that request. Please try again.