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

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

#clear_template_variables!, #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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/staticmatic/base.rb', line 18

def initialize(base_dir, configuration = Configuration.new)
  @configuration = configuration
  @current_page = nil
  @current_file_stack = []
  @base_dir = base_dir
  @src_dir = File.join(@base_dir, "src")
  @site_dir = File.join(@base_dir, "site")
  
  if File.exists?(File.join(@src_dir, "layouts", "application.haml"))
    puts "DEPRECATION: layouts/application.haml will be renamed to layouts/default.haml in 0.12.0"
    @default_layout = "application"
  else
    @default_layout = "default"
  end
  
  @scope = Object.new
  @scope.instance_variable_set("@staticmatic", self)
  
  load_configuration      
  configure_compass

  load_helpers
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration



11
12
13
# File 'lib/staticmatic/base.rb', line 11

def configuration
  @configuration
end

#current_pageObject (readonly)

Returns the value of attribute current_page



12
13
14
# File 'lib/staticmatic/base.rb', line 12

def current_page
  @current_page
end

#site_dirObject (readonly)

Returns the value of attribute site_dir



12
13
14
# File 'lib/staticmatic/base.rb', line 12

def site_dir
  @site_dir
end

#src_dirObject (readonly)

Returns the value of attribute src_dir



12
13
14
# File 'lib/staticmatic/base.rb', line 12

def src_dir
  @src_dir
end

Instance Method Details

#base_dirObject



63
64
65
# File 'lib/staticmatic/base.rb', line 63

def base_dir
  @base_dir
end

#configure_compassObject



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/staticmatic/base.rb', line 94

def configure_compass
  Compass.configuration.project_path = @base_dir 

  compass_config_path = File.join(@base_dir, "config", "compass.rb")
  
  if File.exists?(compass_config_path)
    Compass.add_configuration(compass_config_path)         
  end

  configuration.sass_options.merge!(Compass.configuration.to_sass_engine_options)
end

#current_fileObject



14
15
16
# File 'lib/staticmatic/base.rb', line 14

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

#full_layout_path(name) ⇒ Object



90
91
92
# File 'lib/staticmatic/base.rb', line 90

def full_layout_path(name)
  File.join(@src_dir, "layouts", "#{name}.haml")
end

#layout_exists?(name) ⇒ Boolean



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

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

#load_configurationObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/staticmatic/base.rb', line 42

def load_configuration
  configuration = StaticMatic::Configuration.new
  config_file = File.join(@base_dir, "config", "site.rb")

  if !File.exists?(config_file)
    config_file = File.join(@base_dir, "src", "configuration.rb")

    if File.exists?(config_file)
      puts "DEPRECATION: #{@base_dir}/src/configuration.rb will be moved to #{@base_dir}/config/site.rb in 0.12.0"
    end
  end
  
  if File.exists?(config_file)
    config = File.read(config_file)
    eval(config)
  end

  # Compass.sass_engine_options.merge!(configuration.sass_options)
  @configuration = configuration
end

#run(command) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/staticmatic/base.rb', line 67

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

#template_directory?(path) ⇒ Boolean



86
87
88
# File 'lib/staticmatic/base.rb', line 86

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

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

TODO: DRY this _exists? section up



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

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