Class: Forge::Project

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, task, config = {}, config_file = nil) ⇒ Project

Returns a new instance of Project.



19
20
21
22
23
24
25
26
# File 'lib/forge/project.rb', line 19

def initialize(root, task, config={}, config_file=nil)
  @root        = File.expand_path(root)
  @config      = config || {}
  @task        = task
  @config_file = config_file

  self.load_config if @config.empty?
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



17
18
19
# File 'lib/forge/project.rb', line 17

def config
  @config
end

#rootObject

Returns the value of attribute root.



17
18
19
# File 'lib/forge/project.rb', line 17

def root
  @root
end

#taskObject

Returns the value of attribute task.



17
18
19
# File 'lib/forge/project.rb', line 17

def task
  @task
end

Class Method Details

.create(root, config, task) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/forge/project.rb', line 7

def create(root, config, task)
  root = File.expand_path(root)

  project = self.new(root, task, config)
  Generator.run(project)

  project
end

Instance Method Details

#assets_pathObject



28
29
30
# File 'lib/forge/project.rb', line 28

def assets_path
  @assets_path ||= File.join(self.source_path, 'assets')
end

#build_pathObject



32
33
34
# File 'lib/forge/project.rb', line 32

def build_path
  File.join(self.root, '.forge', 'build')
end

#config_fileObject



56
57
58
# File 'lib/forge/project.rb', line 56

def config_file
  @config_file ||= File.join(self.root, 'config.rb')
end

#functions_pathObject



48
49
50
# File 'lib/forge/project.rb', line 48

def functions_path
  File.join(self.source_path, 'functions')
end

#get_bindingObject



103
104
105
# File 'lib/forge/project.rb', line 103

def get_binding
  binding
end

#global_config_fileObject



60
61
62
# File 'lib/forge/project.rb', line 60

def global_config_file
  @global_config_file ||= File.join(ENV['HOME'], '.forge', 'config.rb')
end

#includes_pathObject



52
53
54
# File 'lib/forge/project.rb', line 52

def includes_path
  File.join(self.source_path, 'includes')
end

Create a symlink from source to the project build dir



65
66
67
68
69
70
71
72
73
# File 'lib/forge/project.rb', line 65

def link(source)
  source = File.expand_path(source)

  unless File.directory?(File.dirname(source))
    raise Forge::LinkSourceDirNotFound
  end

  @task.link_file build_path, source
end

#load_configObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/forge/project.rb', line 79

def load_config
  config = {}

  # Check for global (user) config.rb
  if File.exists?(self.global_config_file)
    config.merge!(load_ruby_config(self.global_config_file))
  end

  # Check for config.rb
  if File.exists?(self.config_file)
    config.merge!(load_ruby_config(self.config_file))
  else
    # Old format of config file
    if File.exists?(File.join(self.root, 'config.json'))
      config.merge!(convert_old_config)
    else
      raise Error, "Could not find the config file, are you sure you're in a
      forge project directory?"
    end
  end

  @config = config
end

#package_pathObject



40
41
42
# File 'lib/forge/project.rb', line 40

def package_path
  File.join(self.root, 'package')
end

#parse_erb(file) ⇒ Object



107
108
109
# File 'lib/forge/project.rb', line 107

def parse_erb(file)
  ERB.new(::File.binread(file), nil, '-', '@output_buffer').result(binding)
end

#source_pathObject



36
37
38
# File 'lib/forge/project.rb', line 36

def source_path
  File.join(self.root, 'source')
end

#templates_pathObject



44
45
46
# File 'lib/forge/project.rb', line 44

def templates_path
  File.join(self.source_path, 'templates')
end

#theme_idObject



75
76
77
# File 'lib/forge/project.rb', line 75

def theme_id
  File.basename(self.root).gsub(/\W/, '_')
end