mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Add New Inline-Template Plugin
Also add inline template for RPC and REST tables
This commit is contained in:
parent
94c1166470
commit
79fd671e90
3 changed files with 87 additions and 11 deletions
61
_plugins/inline-template.rb
Normal file
61
_plugins/inline-template.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
# This file is licensed under the MIT License (MIT) available on
|
||||
# http://opensource.org/licenses/MIT.
|
||||
|
||||
## inline-template.rb reformats inline YAML using a template file from
|
||||
## the _template directory. (File must end in .inline)
|
||||
|
||||
## Example:
|
||||
## {% itemplate %}
|
||||
## ...YAML...
|
||||
## {% enditemplate %}
|
||||
|
||||
module Jekyll
|
||||
|
||||
require 'yaml'
|
||||
|
||||
class InlineTemplateBlock < Liquid::Block
|
||||
|
||||
def initialize(tag_name, text, tokens)
|
||||
super
|
||||
@template_name = '_templates/' + text.gsub(' ','') + '.inline'
|
||||
end
|
||||
|
||||
def render(context)
|
||||
output = super
|
||||
|
||||
data = YAML.load(output)
|
||||
template = File.open(@template_name, mode="r")
|
||||
@mytemplate = Liquid::Template.parse(template.read())
|
||||
@mytemplate.render('entry' => data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Jekyll
|
||||
|
||||
require 'yaml'
|
||||
|
||||
class InlineTemplateBlockDisabled < Liquid::Block
|
||||
|
||||
def initialize(tag_name, text, tokens)
|
||||
super
|
||||
end
|
||||
|
||||
def render(context)
|
||||
output = super
|
||||
|
||||
output
|
||||
#return('Inline Template (itemplate) disabled' + "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
#Do nothing if plugin is disabled
|
||||
if !ENV['ENABLED_PLUGINS'].nil? and ENV['ENABLED_PLUGINS'].index('itemplate').nil?
|
||||
print 'Inline Template (itemplate) disabled' + "\n"
|
||||
Liquid::Template.register_tag('itemplate', Jekyll::InlineTemplateBlockDisabled)
|
||||
else
|
||||
Liquid::Template.register_tag('itemplate', Jekyll::InlineTemplateBlock)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue