class Ocs::Document::Generator

Public Class Methods

documents_path() click to toggle source
# File lib/ocs/document/generator.rb, line 12
def documents_path
  File.expand_path("../../../../docs", __FILE__)
end
library_path() click to toggle source
# File lib/ocs/document/generator.rb, line 16
def library_path
  File.expand_path("../../../", __FILE__)
end
new() click to toggle source
# File lib/ocs/document/generator.rb, line 37
def initialize

end
ocs_path() click to toggle source
# File lib/ocs/document/generator.rb, line 20
def ocs_path
  File.join(library_path, "ocs")
end
patches_path() click to toggle source
# File lib/ocs/document/generator.rb, line 24
def patches_path
  File.join(ocs_path, "document/patches")
end
resource_paths() click to toggle source
# File lib/ocs/document/generator.rb, line 32
def resource_paths
  Dir[File.join(resources_path, "*.rb")]
end
resources_path() click to toggle source
# File lib/ocs/document/generator.rb, line 28
def resources_path
  File.join(ocs_path, "resources")
end

Public Instance Methods

generate() click to toggle source
# File lib/ocs/document/generator.rb, line 41
def generate
  require "ocs/errors"
  Patches.patch("ocs/resources/base")
  self.class.resource_paths.each do |resource|
    name = resource.sub(/^.+\//, "").sub(/\.rb$/, "").camelize
    self.class.resources[name] = {}
    require resource
  end
  output
end

Private Instance Methods

output() click to toggle source
# File lib/ocs/document/generator.rb, line 54
def output
  output_resources
end
output_resources() click to toggle source
# File lib/ocs/document/generator.rb, line 58
def output_resources
  File.write(File.join(self.class.documents_path, "resources.md"), resources_markdown)
end
render_resource_markdown(name, attributes) click to toggle source
# File lib/ocs/document/generator.rb, line 62
def render_resource_markdown(name, attributes)
  p name
  p attributes
  ::Erubis::Eruby.new(resource_template).evaluate(name: name, attributes: attributes)
end
resource_template() click to toggle source
# File lib/ocs/document/generator.rb, line 68
def resource_template
  File.read(File.expand_path("../templates/_resource.md.erb", __FILE__))
end
resources_contents() click to toggle source
# File lib/ocs/document/generator.rb, line 72
def resources_contents
  self.class.resources.map { |name, attributes| render_resource_markdown(name, attributes) }
end
resources_markdown() click to toggle source
# File lib/ocs/document/generator.rb, line 76
def resources_markdown
  ::Erubis::Eruby.new(resources_template).evaluate { resources_contents.join("\n") }
end
resources_template() click to toggle source
# File lib/ocs/document/generator.rb, line 80
def resources_template
  File.read(File.expand_path("../templates/resources.md.erb", __FILE__))
end