Sharing Code with Gist in ExpressionEngine
This is not the article that I originally set out to write. Last week I started an article about the benefits of a Ruby gem that I had started using. The research for the article was going great. I had working code examples and was ready to start writing. Then I hit a road block: How were my code examples going to be displayed?
Time for a minor detour:
The three problems:
- Retrieve a Gist and display it using server-side code. (ExpressionEngine integration required.)
- Be able to call ExpressionEngine tags from content blocks.
- Code examples need to have line numbers.
You can check out my plug-in on GitHub.
Please note that this plug-in has only been tested using ExpressionEngine 2.
ExpressionEngine Tags in Content Blocks
So now I had a shiny new plug-in to pull in my code examples. I tested it out by directly putting in a templates on a development server. When I moved my new tag into the content of an article (by the way, we use WYGWAM) I realized that my new tag was not being executed. I set out to see if I could make this work. Like usual I dove in head first, so I popped open the source code for our rich text area field type and started hacking. I quickly realized that this was not the way to go. Then I jumped into Google and found that the ExpressionEngine core team had thought of this problem and provided a plug-in/tag to handle this situation.
You can find it here.
Now there are several security reasons that you should be careful when using this tag. This allows anyone who has permission to edit content to use any ExpressionEngine tags they want. It does not require much imagination to think of the abuse cases that could open up. I considered these risks and quickly decided that since this was our internal blog, that I could live with the risks.
So now I had my new tag and a way to use it in my article. Things were going great. I decided to show some other Sparkboxers. The first comment was not how cool it was, or how it worked, they just asked why there were no line numbers. This began the third leg of my journey.
|1 2 3 4 5 6 7 8 9 10 11 12 13 14|| |
So there you have it. You should be able to use the above to share code examples from Gist on your ExpressionEngine site. If you were hoping to find my Ruby article, don't worry, it should be done soon and it will have lots of code examples.