Module: Raml

Defined in:
lib/raml.rb,
lib/raml/node.rb,
lib/raml/parser.rb,
lib/raml/version.rb,
lib/raml/node/body.rb,
lib/raml/node/root.rb,
lib/raml/exceptions.rb,
lib/raml/node/trait.rb,
lib/raml/mixin/merge.rb,
lib/raml/node/header.rb,
lib/raml/node/method.rb,
lib/raml/node/schema.rb,
lib/raml/mixin/bodies.rb,
lib/raml/mixin/global.rb,
lib/raml/mixin/parent.rb,
lib/raml/mixin/headers.rb,
lib/raml/node/resource.rb,
lib/raml/node/response.rb,
lib/raml/node/template.rb,
lib/raml/node/reference.rb,
lib/raml/mixin/validation.rb,
lib/raml/mixin/documentable.rb,
lib/raml/node/documentation.rb,
lib/raml/node/resource_type.rb,
lib/raml/node/abstract_method.rb,
lib/raml/node/trait_reference.rb,
lib/raml/node/schema_reference.rb,
lib/raml/node/abstract_resource.rb,
lib/raml/node/parametized_reference.rb,
lib/raml/node/parameter/uri_parameter.rb,
lib/raml/node/resource_type_reference.rb,
lib/raml/node/parameter/form_parameter.rb,
lib/raml/node/parameter/query_parameter.rb,
lib/raml/node/parameter/abstract_parameter.rb,
lib/raml/node/parameter/base_uri_parameter.rb

Defined Under Namespace

Modules: Bodies, Documentable, Global, Headers, Merge, Parameter, Parent, Validation Classes: AbstractMethod, AbstractResource, Body, CantIncludeFile, Documentation, Header, InapplicableParameterAttribute, InvalidMediaType, InvalidMethod, InvalidParameterAttribute, InvalidParameterType, InvalidParent, InvalidProperty, InvalidSchema, MergeError, Method, Node, ParametizedReference, Parser, PropertiesNode, RamlError, Reference, RequiredPropertyMissing, Resource, ResourceType, ResourceTypeReference, Response, Root, Schema, SchemaReference, Template, Trait, TraitReference, UnknownProperty, UnknownResourceTypeReference, UnknownTraitReference, UnknownTypeOrTraitParamFunction, UnknownTypeOrTraitParameter, UnsupportedRamlVersion, ValueNode

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.document(filepath, out_file = nil) ⇒ String

Parses RAML from a file and generates API documentation in HTML. If no output filename argument is given, the HTML is returned as a string. If an output filename argument is given, the HTML is stored to a file at that location.

Parameters:

  • filepath (String)

    the file path of the file containing RAML.

  • out_file (String) (defaults to: nil)

    the file path of the file to write the documentation to. Defaults to nil.

Returns:

  • (String)

    the HTML documentation, if out_file is nil.

Raises:

  • (Errno::ENOENT)

    if the file can’t be found.

  • (Errno::EACCES)

    if the files can’t be read or written.

  • (RamlError)

    if the RAML is invalid.



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/raml.rb', line 92

def self.document(filepath, out_file=nil)
  root = parse_file filepath
  root.expand

  if out_file
    File.open(out_file, 'w') do |file|
      file.write root.document
    end
  else
    root.document
  end
end

.parse(raml) ⇒ Raml::Root

Parses RAML from a string.

Parameters:

  • raml (String)

    the string containing RAML.

Returns:

Raises:



60
61
62
# File 'lib/raml.rb', line 60

def self.parse(raml)
  Raml::Parser.parse raml
end

.parse_file(filepath) ⇒ Raml::Root

Parses RAML from a file.

Parameters:

  • filepath (String)

    the file path of the file containing RAML.

Returns:

Raises:

  • (Errno::ENOENT)

    if the file can’t be found.

  • (Errno::EACCES)

    if the file can’t be read.

  • (RamlError)

    if the RAML is invalid.



71
72
73
74
75
76
77
78
79
# File 'lib/raml.rb', line 71

def self.parse_file(filepath)
  file = File.new filepath
  raise UnsupportedRamlVersion unless file.readline =~ /\A#%RAML 0.8\s*\z/
  
  path = File.dirname filepath
  path = nil if path == ''
  
  Raml::Parser.parse file.read, path
end