Class: ProScribe::Project

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Project

Returns a new instance of Project.



15
16
17
18
19
20
21
22
23
# File 'lib/proscribe/project.rb', line 15

def initialize(config_file)
  @root   = File.dirname(config_file)
  @config = Hashie::Mash.new(YAML::load_file(config_file))

  # Defaults
  @config.manual  ||= '.'
  @config.output  ||= 'doc'
  @config.files   ||= Array.new
end

Instance Attribute Details

#configObject (readonly)

Attribute: config (ProScribe::Project) Returns a hash of the project’s configuration, pulled from Scribefile.



13
14
15
# File 'lib/proscribe/project.rb', line 13

def config
  @config
end

Instance Method Details

#dir(*a) ⇒ Object

Attribute: dir (ProScribe::Project) Returns the path to the temporary Proton project.



85
86
87
88
89
90
91
92
93
94
# File 'lib/proscribe/project.rb', line 85

def dir(*a)
  @dir ||= begin
    dir = File.join(Dir.tmpdir, File.basename(root) + Time.now.to_i.to_s)
    FileUtils.rm_rf dir
    FileUtils.mkdir_p dir
    dir
  end

  File.join(@dir, *a)
end

#makeObject

Method: make (ProScribe::Project) Creates the temp dir from the project’s manual and inline comments.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/proscribe/project.rb', line 46

def make
  dir

  # Copy the files over
  copy_files ProScribe.root('data/default/'), dir

  # Copy manual files over
  copy_files manual_path, dir, :except => ['Gemfile', 'Gemfile.lock', 'config.ru']

  # Merge Scribefile into Protonfile
  File.open(File.join(dir, 'Protonfile'), 'w') { |f| f.write protonfile }

  # Extract block comments
  config.files.each do |group|
    ex = ProScribe::Extractor.new(Dir[root(group.source)], root)
    ex.write! File.join(dir, group.prefix || '')
  end
end

#manual_pathObject

Attribute: manual_path (ProScribe::Project) Returns the absolute path to the projects’s manual.



39
40
41
# File 'lib/proscribe/project.rb', line 39

def manual_path
  root(@config.manual)
end

#protonfileObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/proscribe/project.rb', line 65

def protonfile
  yaml = YAML::load_file(ProScribe.root('data/default/Protonfile'))

  # Copy from Scribefile
  c = config.to_hash.dup
  c.delete 'manual'
  c.delete 'output'
  c.delete 'files'

  # Add some things
  c['git'] = `git rev-parse HEAD`.strip

  yaml.merge! c

  YAML::dump yaml
end

#root(*a) ⇒ Object

Attribute: root (ProScribe::Project) Returns the root path.

## Usage

project.root
project.root(*args)


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

def root(*a)
  File.join(@root, *a)
end