Class: ProcessIt::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of 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/processit/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/processit/base.rb', line 11

def configuration
  @configuration
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



12
13
14
# File 'lib/processit/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/processit/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/processit/base.rb', line 12

def src_dir
  @src_dir
end

Instance Method Details

#base_dirObject



62
63
64
# File 'lib/processit/base.rb', line 62

def base_dir
  @base_dir
end

#configure_compassObject



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

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/processit/base.rb', line 14

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

#full_layout_path(name) ⇒ Object



89
90
91
# File 'lib/processit/base.rb', line 89

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

#layout_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/processit/base.rb', line 81

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
# File 'lib/processit/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

  @configuration = configuration
end

#run(command) ⇒ Object



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

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

Returns:

  • (Boolean)


85
86
87
# File 'lib/processit/base.rb', line 85

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)


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

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