Class: CodeHighlight::MainController
- Inherits:
-
Volt::ModelController
- Object
- Volt::ModelController
- CodeHighlight::MainController
- Defined in:
- app/code_highlight/controllers/main_controller.rb
Instance Method Summary collapse
- #before_index_remove ⇒ Object
- #code_tag ⇒ Object
- #highlight ⇒ Object
- #index_ready ⇒ Object
-
#update_code ⇒ Object
Since the contents of the <code> tag will be replaced by highlight.js, we can’t use a content binding, instead we use jquery to insert the html, and then highlight it after each insert.
Instance Method Details
#before_index_remove ⇒ Object
18 19 20 |
# File 'app/code_highlight/controllers/main_controller.rb', line 18 def before_index_remove @watcher.stop if @watcher end |
#code_tag ⇒ Object
22 23 24 |
# File 'app/code_highlight/controllers/main_controller.rb', line 22 def code_tag first_element end |
#highlight ⇒ Object
26 27 28 29 30 |
# File 'app/code_highlight/controllers/main_controller.rb', line 26 def highlight `hljs.configure({useBR: true});` block = code_tag `hljs.highlightBlock(block);` end |
#index_ready ⇒ Object
14 15 16 |
# File 'app/code_highlight/controllers/main_controller.rb', line 14 def index_ready @watcher = -> { update_code }.watch! end |
#update_code ⇒ Object
Since the contents of the <code> tag will be replaced by highlight.js, we can’t use a content binding, instead we use jquery to insert the html, and then highlight it after each insert. We use a .watch! to update the code.
7 8 9 10 11 12 |
# File 'app/code_highlight/controllers/main_controller.rb', line 7 def update_code html = yield_html `$(#{code_tag}).html(html);` highlight end |