Class: Alister::Site

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

Overview

Main site builder use this to build your site

Examples:

A simple site

s = Alister::Site.new
s.route '/', pageroot_page
s.route '/about/', pageabout_page
s.build("./build")

s.file '/main.css', scss_string
s.build_and_reset("./build")
s.assets do
  source "./assets"
  enable_webp_conversion unless DEBUG
  file "**/*"
  build_to_and_reset "./build/assets/"

  source "./additions"
  files "robots.txt", "not_found.html"
  build_to_and_reset "./build/"
end

Defined Under Namespace

Classes: Page

Instance Method Summary collapse

Constructor Details

#initializeSite



29
30
31
32
33
# File 'lib/site.rb', line 29

def initialize
  @path = nil
  @routes = []
  @files = []
end

Instance Method Details

#assets { ... } ⇒ void

This method returns an undefined value.

Create assets easier

Examples:

s = Alister::Site.new
s.assets do
  source "./assets"
  enable_webp_conversion unless DEBUG
  file "**/*"
  build_to_and_reset "./build/assets/"
end

Yields:

  • Start block of asset



78
79
80
81
# File 'lib/site.rb', line 78

def assets(&block)
  assets = Alister::Assets.new
  assets.instance_eval(&block)
end

#build_to(path) ⇒ void Also known as: build

This method returns an undefined value.

Builds the site



54
55
56
57
58
59
60
61
62
63
# File 'lib/site.rb', line 54

def build_to(path)
  @path = path
  @routes.each do |route|
    create_file(route, 'index.html')
  end
  @files.each do |file|
    create_file(file)
  end
  puts '[LOG] Finished creating files'
end

#build_to_and_reset(path) ⇒ void Also known as: build_and_reset

This method returns an undefined value.

Builds and then resets the site builder



94
95
96
97
# File 'lib/site.rb', line 94

def build_to_and_reset(path)
  build_to(path)
  reset
end

#file(path, string) ⇒ void

This method returns an undefined value.

Creates a new file on path



47
48
49
# File 'lib/site.rb', line 47

def file(path, string)
  @files << Page.new(path, string)
end

#resetvoid

This method returns an undefined value.

Resets the site builder for next build



85
86
87
88
89
# File 'lib/site.rb', line 85

def reset
  @path = nil
  @routes = []
  @files = []
end

#route(path, page) ⇒ void

This method returns an undefined value.

Creates a new html page on path



39
40
41
# File 'lib/site.rb', line 39

def route(path, page)
  @routes << Page.new(path, page)
end