Module: Sassdoc

Defined in:
lib/sassdoc.rb

Class Method Summary collapse

Class Method Details

.init(read, options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sassdoc.rb', line 20

def self.init(read, options)
  pwd = FileUtils.pwd()
  json = self.parse(ARGV[0] || '.').to_json
  if options[:stdout]
    puts json
  else
    Dir.chdir(pwd)
    @json_filename = 'sassdoc.json'
    dir = options[:destination]
    FileUtils.mkdir_p dir
    json_file = File.join(dir, @json_filename)
    FileUtils.touch json_file
    File.open(json_file, "w") {|file| file.puts json}
    if options[:viewer]
      # copy over viewer files
      FileUtils.cp_r(File.join(File.dirname(__FILE__), '..', 'viewer', '.'), dir)
      settings = {}
      settings[:viewer] = options[:scm] if options[:scm]
      settings[:docs] = @json_filename
      settings = settings.to_json
      %w(index.html tmpl/view.tmpl).each do |src|
        src = File.join(dir, src)
        text = File.read(src)
        File.open(src, "w") {|file| file.puts text.gsub(/\{SASSDOC_TITLE\}/, options[:name]).gsub(/\{SASSDOC_SETTINGS\}/, settings)}
      end
    end
  end
end

.parse(read) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sassdoc.rb', line 6

def self.parse(read)
  if File.exist? read
    if File.directory? read and Dir.chdir(read)
      # loop through each scss file in the directory
      Dir.glob('**/*.s[ac]ss').each do |f|
        self.parse_docs(f)
      end
    else
      self.parse_docs(read)
    end
  end
  return @docs
end