Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.

Commit b5cf8b9

Browse files
committed
Merge pull request #196 from dgeb/coderay-handlebars
Custom handlebars syntax highlighter for coderay
2 parents 334405f + 24e7791 commit b5cf8b9

File tree

6 files changed

+72
-72
lines changed

6 files changed

+72
-72
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem "redcarpet"
44
gem "activesupport"
55
gem "highline"
66
gem "rake"
7-
gem "coderay"
7+
gem "coderay", :git => "git://github.com/dgeb/coderay.git", :branch => "handlebars"
88
gem "middleman", '~> 3.0'
99
gem "middleman-blog", "~> 3.0"
1010
gem "thin"

Gemfile.lock

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
GIT
2+
remote: git://github.com/dgeb/coderay.git
3+
revision: 73767aa80301ef5de74f625d597dde5cd940e74d
4+
branch: handlebars
5+
specs:
6+
coderay (1.0.8.rc1)
7+
18
GEM
29
remote: http://rubygems.org/
310
specs:
@@ -6,7 +13,6 @@ GEM
613
multi_json (~> 1.0)
714
builder (3.1.3)
815
chunky_png (1.2.5)
9-
coderay (1.0.7)
1016
coffee-script (2.2.0)
1117
coffee-script-source
1218
execjs
@@ -119,7 +125,7 @@ PLATFORMS
119125
DEPENDENCIES
120126
activesupport
121127
builder
122-
coderay
128+
coderay!
123129
highline
124130
listen
125131
middleman (~> 3.0)

lib/highlighter.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ def registered(app)
1111

1212
module Helpers
1313
def _highlight(string, language, class_name=nil)
14-
language_class = language
15-
language = 'html' if language == 'handlebars'
16-
17-
result = %Q{<div class="highlight #{language_class} #{class_name}">}
14+
result = %Q{<div class="highlight #{language} #{class_name}">}
1815
result += '<div class="ribbon"></div>'
1916
code = string.gsub(/^\n+/, '').rstrip
2017
code = CodeRay.scan(code, language)
@@ -23,7 +20,7 @@ def _highlight(string, language, class_name=nil)
2320
line_number_anchors: false
2421

2522
result += %Q{</div>}
26-
result
23+
result
2724
end
2825

2926
def highlight(language, class_name, &block)

source/about.html.erb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,18 @@ App.Person = DS.Model.extend({
7171

7272
App.peopleController = Em.ArrayController.create({
7373
content: App.Person.findAll()
74-
});<% end %>
74+
});
75+
<% end %>
7576

76-
<% highlight :html, :right do %>
77+
<% highlight :handlebars, :right do %>
7778
<h1>People</h1>
7879

7980
<ul>
8081
{{#each peopleController}}
8182
<li>Hello, <b>{{fullName}}</b>!</li>
8283
{{/each}}
8384
</ul>
84-
85-
86-
87-
88-
<% end %>
85+
<% end %>
8986

9087
</div>
9188

source/docs/handlebars.md

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -667,42 +667,42 @@ Ember comes pre-packaged with a set of views for building a few basic controls l
667667
They are:
668668

669669
####Ember.Checkbox
670-
670+
671671
```handlebars
672-
<label>
673-
{{view Ember.Checkbox checkedBinding="content.isDone"}}
674-
{{content.title}}
675-
</label>
672+
<label>
673+
{{view Ember.Checkbox checkedBinding="content.isDone"}}
674+
{{content.title}}
675+
</label>
676676
```
677-
677+
678678
####Ember.TextField
679-
679+
680680
```javascript
681-
App.MyText = Ember.TextField.extend({
682-
formBlurredBinding: 'App.adminController.formBlurred',
683-
change: function(evt) {
684-
this.set('formBlurred', true);
685-
}
686-
});
681+
App.MyText = Ember.TextField.extend({
682+
formBlurredBinding: 'App.adminController.formBlurred',
683+
change: function(evt) {
684+
this.set('formBlurred', true);
685+
}
686+
});
687687
```
688-
688+
689689
####Ember.Select
690-
690+
691691
```handlebars
692-
{{view Ember.Select viewName="select"
693-
contentBinding="App.peopleController"
694-
optionLabelPath="content.fullName"
695-
optionValuePath="content.id"
696-
prompt="Pick a person:"
697-
selectionBinding="App.selectedPersonController.person"}}
692+
{{view Ember.Select viewName="select"
693+
contentBinding="App.peopleController"
694+
optionLabelPath="content.fullName"
695+
optionValuePath="content.id"
696+
prompt="Pick a person:"
697+
selectionBinding="App.selectedPersonController.person"}}
698698
```
699-
699+
700700
####Ember.TextArea
701-
701+
702702
```javascript
703-
var textArea = Ember.TextArea.create({
704-
valueBinding: 'TestObject.value'
705-
});
703+
var textArea = Ember.TextArea.create({
704+
valueBinding: 'TestObject.value'
705+
});
706706
```
707707

708708

@@ -714,29 +714,26 @@ Example:
714714

715715
```javascript
716716
App.MyText = Ember.TextField.extend({
717-
formBlurredBinding: 'App.adminController.formBlurred',
718-
change: function(evt) {
719-
this.set('formBlurred', true);
720-
}
721-
});
717+
formBlurredBinding: 'App.adminController.formBlurred',
718+
change: function(evt) {
719+
this.set('formBlurred', true);
720+
}
721+
});
722722
```
723723

724-
You can then use this view as a sub view and capture the events. In the following example, a change to the Name input would blurr the form and cause the save button to appear.
725-
726-
```handlebars
727-
<script id="formDetail" data-template-name='formDetail' type="text/x-handlebars">
728-
<form>
729-
<fieldset>
730-
<legend>Info:</legend>
731-
732-
{{view App.MyText name="Name" id="Name" valueBinding="myObj.Name"}}
733-
<label for="Name">Name</label><br/>
734-
735-
{{#if formBlurred}}
736-
<a href="#" {{action "syncData" on="click"}}>Save</a>
737-
{{/if}}
738-
739-
</fieldset>
740-
</form>
741-
</script>
724+
You can then use this view as a sub view and capture the events. In the following example, a change to the Name input would blur the form and cause the save button to appear.
725+
726+
```handlebars
727+
<form>
728+
<fieldset>
729+
<legend>Info:</legend>
730+
731+
{{view App.MyText name="Name" id="Name" valueBinding="myObj.Name"}}
732+
<label for="Name">Name</label><br/>
733+
734+
{{#if formBlurred}}
735+
<a href="#" {{action "syncData" on="click"}}>Save</a>
736+
{{/if}}
737+
</fieldset>
738+
</form>
742739
```

source/stylesheets/highlight.css.scss

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ $border-radius: 5px;
2222
height: 20px;
2323
}
2424

25-
&.javascript .ribbon {
26-
background-image: url(/images/js-ribbon.png);
27-
}
28-
29-
&.html .ribbon {
30-
background-image: url(/images/html-ribbon.png);
31-
}
25+
&.javascript .ribbon {
26+
background-image: url(/images/js-ribbon.png);
27+
}
28+
&.html .ribbon {
29+
background-image: url(/images/html-ribbon.png);
30+
}
31+
/* TODO - create custom handlebars-ribbon.png */
32+
&.handlebars .ribbon {
33+
background-image: url(/images/html-ribbon.png);
34+
}
3235
}
3336

3437
.CodeRay {
@@ -53,7 +56,7 @@ $border-radius: 5px;
5356

5457
/* HTML */
5558
.CodeRay {
56-
.tag {
59+
.tag, .error {
5760
color: red;
5861
}
5962

0 commit comments

Comments
 (0)