Class: JekyllPageBoilerplate::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_page_boilerplate/page.rb

Constant Summary collapse

BOILERPLATES_PATH =
'_boilerplates'
READ_CONFIG_REGEX =
/[\r\n\s]{0,}^_boilerplate:(\s*^[\t ]{1,2}.+$)+[\r\s\n]{0,}(?![^\r\s\n])/
READ_FILE_REGEX =
/^-{3}\s*^(?<head>[\s\S]*)^-{3}\s^(?<body>[\s\S]*)/
TAGS_REGEX =
/\{{2}\s{0,}boilerplate\.([^\{\}\.\s]+)\s{0,}\}{2}/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(boilerplate, custom_args, options) ⇒ Page

Returns a new instance of Page.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll_page_boilerplate/page.rb', line 23

def initialize boilerplate, custom_args, options
  plate_path = get_boilerplate_path(boilerplate)
  abort_unless_file_exists( plate_path )

  parsed_file = {}
  File.open(plate_path, 'r') do |file|
    parsed_file = file.read.match(READ_FILE_REGEX).named_captures
  end

  @tags = JekyllPageBoilerplate::Tags.new(
    defaults(plate_path),
    get_header_config(parsed_file['head']),
    options,
    parse_custom_args(custom_args)
  )
  @tags[:file] = '{{ date }}-{{ slug }}{{ suffix }}' if @tags.timestamp
  @tags.fill(:slug, :file, safe: true)
  @tags.fill(:path, safe: false)

  @head = get_head(parsed_file['head'])
  @body = parsed_file['body']
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



15
16
17
# File 'lib/jekyll_page_boilerplate/page.rb', line 15

def tags
  @tags
end

Class Method Details

.run(boilerplate, custom_args, options) ⇒ Object



17
18
19
20
21
# File 'lib/jekyll_page_boilerplate/page.rb', line 17

def self.run boilerplate, custom_args, options
  page = self.new(boilerplate, custom_args, options)
  page.create
  return "Created "+ File.join(page.tags['path'], page.tags['file'])
end

Instance Method Details

#createObject



46
47
48
49
50
51
52
53
# File 'lib/jekyll_page_boilerplate/page.rb', line 46

def create
  FileUtils.mkdir_p(@tags.path)

  scan_template :@body
  scan_template :@head

  create_new_page
end