Class: StaticMatic::Base

Inherits:
Object
  • Object
show all
Includes:
BuildMixin, HelpersMixin, RenderMixin, RescueMixin, ServerMixin, SetupMixin
Defined in:
lib/staticmatic/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RescueMixin

#render_rescue_from_error

Methods included from ServerMixin

#preview

Methods included from HelpersMixin

#load_helper, #load_helpers

Methods included from SetupMixin

#setup

Methods included from BuildMixin

#build, #build_css, #build_html, #copy_file, #generate_site_file, #save_page, #save_stylesheet

Methods included from RenderMixin

#determine_layout, #generate_css, #generate_html, #generate_html_from_template_source, #generate_html_with_layout, #generate_partial, #source_for_layout, #source_template_from_path

Constructor Details

#initialize(base_dir, configuration = Configuration.new) ⇒ Base

Returns a new instance of Base.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/staticmatic/base.rb', line 38

def initialize(base_dir, configuration = Configuration.new)
  @configuration = configuration
  @current_page = nil
  @current_file_stack = []
  @base_dir = base_dir
  @src_dir = "#{@base_dir}/src"
  @site_dir = "#{@base_dir}/site"
  @templates_dir = File.dirname(__FILE__) + '/templates/default/'
  @layout = "application"
  @scope = Object.new
  @scope.instance_variable_set("@staticmatic", self)
  load_helpers
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



31
32
33
# File 'lib/staticmatic/base.rb', line 31

def configuration
  @configuration
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



32
33
34
# File 'lib/staticmatic/base.rb', line 32

def current_page
  @current_page
end

#site_dirObject (readonly)

Returns the value of attribute site_dir.



32
33
34
# File 'lib/staticmatic/base.rb', line 32

def site_dir
  @site_dir
end

#src_dirObject (readonly)

Returns the value of attribute src_dir.



32
33
34
# File 'lib/staticmatic/base.rb', line 32

def src_dir
  @src_dir
end

Class Method Details

.base_dirsObject



82
83
84
# File 'lib/staticmatic/base.rb', line 82

def base_dirs
  StaticMatic::BASE_DIRS
end

Instance Method Details

#base_dirObject



52
53
54
# File 'lib/staticmatic/base.rb', line 52

def base_dir
  @base_dir
end

#current_fileObject



34
35
36
# File 'lib/staticmatic/base.rb', line 34

def current_file
  @current_file_stack[0] || ""
end

#full_layout_path(name) ⇒ Object



77
78
79
# File 'lib/staticmatic/base.rb', line 77

def full_layout_path(name)
  "#{@src_dir}/layouts/#{name}.haml"
end

#layout_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/staticmatic/base.rb', line 69

def layout_exists?(name)
  File.exists? full_layout_path(name)
end

#run(command) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/staticmatic/base.rb', line 56

def run(command)
  if %w(build setup preview).include?(command)
    send(command)
  else
    puts "#{command} is not a valid StaticMatic command"
  end
end

#template_directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/staticmatic/base.rb', line 73

def template_directory?(path)
  File.directory?(File.join(@src_dir, 'pages', path))
end

#template_exists?(name, dir = '') ⇒ Boolean

TODO: DRY this _exists? section up

Returns:

  • (Boolean)


65
66
67
# File 'lib/staticmatic/base.rb', line 65

def template_exists?(name, dir = '')
  File.exists?(File.join(@src_dir, 'pages', dir, "#{name}.haml")) || File.exists?(File.join(@src_dir, 'stylesheets', "#{name}.sass"))
end