Class: Jekyll::IncludeCode

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/ext.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ IncludeCode

Returns a new instance of IncludeCode.



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ext.rb', line 196

def initialize(tag_name, text, tokens)

  rootPath = $g_config['code_root_path'] || 'static'
  if text.start_with?("/")
    filePath = "#{text}"[1..-1].strip()
  else
    filePath = "#{rootPath}/#{text}".strip()
  end
  filePath = File.expand_path(filePath)
  puts "--------- include code: #{filePath}"
  
  begin
    file = File.open(filePath)
    @filecontent = file.read()
  rescue => exception
    puts exception
    @filecontent = "load file:#{filePath} failed"
    
  end
  
end

Instance Method Details

#render(context) ⇒ Object



218
219
220
221
222
223
224
225
226
# File 'lib/ext.rb', line 218

def render(context)
  s="``````"
  r= <<EOF
#{s}
#{@filecontent}
#{s}
EOF
  return r
end