Class: Jekyll::IncludeRaw
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::IncludeRaw
- Defined in:
- lib/ext.rb
Constant Summary collapse
- Syntax =
/\s*file\s*=\s*(\S+)/
Instance Method Summary collapse
- #getPath(text, context) ⇒ Object
-
#initialize(tag_name, text, tokens) ⇒ IncludeRaw
constructor
A new instance of IncludeRaw.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ IncludeRaw
Returns a new instance of IncludeRaw.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/ext.rb', line 268 def initialize(tag_name, text, tokens) @file = "" @dynamicFile = "" if text =~ Syntax dynfile = Regexp.last_match(1) @dynamicFile = dynfile.gsub(/^['"]|['"]$/, '') else @filename = text.gsub(/^['"]|['"]$/, '') end end |
Instance Method Details
#getPath(text, context) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/ext.rb', line 234 def getPath(text,context) rootPath = $g_config['code_root_path'] || 'static' if text.start_with?("/") filePath = "#{text}"[1..-1].strip() filePath = File.(filePath) elsif text.start_with?("@") # _include/ filePath = "#{text}"[1..-1].strip() site = context.registers[:site] user_include_path = File.join(site.source, "_includes", filePath) site = Jekyll.sites.first # 或你自己已有的 site theme = site.theme themeroot = theme.root # 就是当前主题的根目录 plugin_include_file = File.join(themeroot, "_includes/" + filePath) if File.exist?(user_include_path) filePath = user_include_path elsif File.exist?(plugin_include_file) filePath = plugin_include_file else filePath = user_include_path end else filePath = "#{rootPath}/#{text}".strip() filePath = File.(filePath) end return filePath end |
#render(context) ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/ext.rb', line 284 def render(context) filePath = @filename if @dynamicFile.length > 1 filePath = context[@dynamicFile] end filePath = getPath(filePath,context) puts "include_raw :#{filePath} failed #{@dynamicFile}" begin file = File.open(filePath) return file.read() rescue => exception puts exception return "Load file:#{filePath} failed #{@dynamicFile}" end end |