Class: Forge::Project
- Inherits:
-
Object
- Object
- Forge::Project
- Defined in:
- lib/forge/project.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#root ⇒ Object
Returns the value of attribute root.
-
#task ⇒ Object
Returns the value of attribute task.
Class Method Summary collapse
Instance Method Summary collapse
- #assets_path ⇒ Object
- #build_path ⇒ Object
- #config_file ⇒ Object
- #functions_path ⇒ Object
- #get_binding ⇒ Object
- #global_config_file ⇒ Object
- #includes_path ⇒ Object
-
#initialize(root, task, config = {}, config_file = nil) ⇒ Project
constructor
A new instance of Project.
-
#link(source) ⇒ Object
Create a symlink from source to the project build dir.
- #load_config ⇒ Object
- #package_path ⇒ Object
- #parse_erb(file) ⇒ Object
- #source_path ⇒ Object
- #templates_path ⇒ Object
- #theme_id ⇒ Object
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.(root) @config = config || {} @task = task @config_file = config_file self.load_config if @config.empty? end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
17 18 19 |
# File 'lib/forge/project.rb', line 17 def config @config end |
#root ⇒ Object
Returns the value of attribute root.
17 18 19 |
# File 'lib/forge/project.rb', line 17 def root @root end |
#task ⇒ Object
Returns the value of attribute task.
17 18 19 |
# File 'lib/forge/project.rb', line 17 def task @task end |
Class Method Details
Instance Method Details
#assets_path ⇒ Object
28 29 30 |
# File 'lib/forge/project.rb', line 28 def assets_path @assets_path ||= File.join(self.source_path, 'assets') end |
#build_path ⇒ Object
32 33 34 |
# File 'lib/forge/project.rb', line 32 def build_path File.join(self.root, '.forge', 'build') end |
#config_file ⇒ Object
56 57 58 |
# File 'lib/forge/project.rb', line 56 def config_file @config_file ||= File.join(self.root, 'config.rb') end |
#functions_path ⇒ Object
48 49 50 |
# File 'lib/forge/project.rb', line 48 def functions_path File.join(self.source_path, 'functions') end |
#get_binding ⇒ Object
103 104 105 |
# File 'lib/forge/project.rb', line 103 def get_binding binding end |
#global_config_file ⇒ Object
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_path ⇒ Object
52 53 54 |
# File 'lib/forge/project.rb', line 52 def includes_path File.join(self.source_path, 'includes') end |
#link(source) ⇒ Object
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.(source) unless File.directory?(File.dirname(source)) raise Forge::LinkSourceDirNotFound end @task.link_file build_path, source end |
#load_config ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
36 37 38 |
# File 'lib/forge/project.rb', line 36 def source_path File.join(self.root, 'source') end |
#templates_path ⇒ Object
44 45 46 |
# File 'lib/forge/project.rb', line 44 def templates_path File.join(self.source_path, 'templates') end |
#theme_id ⇒ Object
75 76 77 |
# File 'lib/forge/project.rb', line 75 def theme_id File.basename(self.root).gsub(/\W/, '_') end |