Class: Guides::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/guides/generator.rb

Constant Summary collapse

EXTENSIONS =
%w(textile md html.erb)
GUIDES_RE =
/\.(?:#{EXTENSIONS.map{|e| Regexp.escape(e)}.join('|')})$/
LOCAL_ASSETS =
File.expand_path("../templates/assets", __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Generator

Returns a new instance of Generator.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/guides/generator.rb', line 68

def initialize(options)
  @options = options

  @guides_dir = File.expand_path(Dir.pwd)
  @source_dir = File.join(@guides_dir, "source")
  @output_dir = File.join(@guides_dir, options[:production] ? "output" : "staging")

  FileUtils.mkdir_p(@output_dir)

  @edge     = options[:edge]
  @warnings = options[:warnings]
  @all      = options[:all]
  @production = options[:production]

  @meta = Guides.meta
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



62
63
64
# File 'lib/guides/generator.rb', line 62

def all
  @all
end

#edgeObject (readonly)

Returns the value of attribute edge.



62
63
64
# File 'lib/guides/generator.rb', line 62

def edge
  @edge
end

#guides_dirObject (readonly)

Returns the value of attribute guides_dir.



62
63
64
# File 'lib/guides/generator.rb', line 62

def guides_dir
  @guides_dir
end

#output_dirObject (readonly)

Returns the value of attribute output_dir.



62
63
64
# File 'lib/guides/generator.rb', line 62

def output_dir
  @output_dir
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



62
63
64
# File 'lib/guides/generator.rb', line 62

def source_dir
  @source_dir
end

#warningsObject (readonly)

Returns the value of attribute warnings.



62
63
64
# File 'lib/guides/generator.rb', line 62

def warnings
  @warnings
end

Instance Method Details

#construction?(source_file) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
# File 'lib/guides/generator.rb', line 90

def construction?(source_file)
  # TODO: Clean this up a bit, it is messy
  url = source_file.sub(/\.(#{EXTENSIONS.map{|e| Regexp.escape(e) }.join('|')})$/, '')
  guide = @meta['index'].values.flatten.select{|g| g['url'] == url }.first rescue nil
  guide && guide['construction']
end

#generateObject



85
86
87
88
# File 'lib/guides/generator.rb', line 85

def generate
  generate_guides
  copy_assets
end