Class: Marv::Project
- Inherits:
-
Object
- Object
- Marv::Project
- Defined in:
- lib/marv/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
- #project_id ⇒ Object
- #project_php_file ⇒ Object
- #source_path ⇒ Object
- #templates_path ⇒ Object
Constructor Details
#initialize(root, task, config = {}, config_file = nil) ⇒ Project
19 20 21 22 23 24 25 26 |
# File 'lib/marv/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/marv/project.rb', line 17 def config @config end |
#root ⇒ Object
Returns the value of attribute root.
17 18 19 |
# File 'lib/marv/project.rb', line 17 def root @root end |
#task ⇒ Object
Returns the value of attribute task.
17 18 19 |
# File 'lib/marv/project.rb', line 17 def task @task end |
Class Method Details
Instance Method Details
#assets_path ⇒ Object
28 29 30 |
# File 'lib/marv/project.rb', line 28 def assets_path @assets_path ||= File.join(self.source_path, 'assets') end |
#build_path ⇒ Object
32 33 34 |
# File 'lib/marv/project.rb', line 32 def build_path File.join(self.root, '.watch', 'build') end |
#config_file ⇒ Object
56 57 58 |
# File 'lib/marv/project.rb', line 56 def config_file @config_file ||= File.join(self.root, 'config.rb') end |
#functions_path ⇒ Object
48 49 50 |
# File 'lib/marv/project.rb', line 48 def functions_path File.join(self.source_path, 'functions') end |
#get_binding ⇒ Object
109 110 111 |
# File 'lib/marv/project.rb', line 109 def get_binding binding end |
#global_config_file ⇒ Object
60 61 62 |
# File 'lib/marv/project.rb', line 60 def global_config_file @global_config_file ||= File.join(ENV['HOME'], '.marv', 'config.rb') end |
#includes_path ⇒ Object
52 53 54 |
# File 'lib/marv/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 74 75 76 77 78 79 |
# File 'lib/marv/project.rb', line 65 def link(source) source = File.(source) unless File.writable?(File.dirname(source)) @task.say "Permission Denied!", :red @task.say "You do not have write permissions for the destination folder" abort end unless File.directory?(File.dirname(source)) raise Marv::LinkSourceDirNotFound end @task.link_file build_path, source end |
#load_config ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/marv/project.rb', line 89 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 @task.say "Could not find the config file!", :red @task.say "Are you sure you're in a marv project directory?" abort end @config = config end |
#package_path ⇒ Object
40 41 42 |
# File 'lib/marv/project.rb', line 40 def package_path File.join(self.root, 'package') end |
#parse_erb(file) ⇒ Object
113 114 115 |
# File 'lib/marv/project.rb', line 113 def parse_erb(file) ERB.new(::File.binread(file), nil, '-', '@output_buffer').result(binding) end |
#project_id ⇒ Object
81 82 83 |
# File 'lib/marv/project.rb', line 81 def project_id File.basename(self.root).gsub(/\W/, '_') end |
#project_php_file ⇒ Object
85 86 87 |
# File 'lib/marv/project.rb', line 85 def project_php_file "#{File.basename(self.root).gsub(/\W/, '-').downcase}.php" end |
#source_path ⇒ Object
36 37 38 |
# File 'lib/marv/project.rb', line 36 def source_path File.join(self.root, 'source') end |
#templates_path ⇒ Object
44 45 46 |
# File 'lib/marv/project.rb', line 44 def templates_path File.join(self.source_path, 'templates') end |