Class: Jazzy::SourceDocument

Inherits:
SourceDeclaration show all
Defined in:
lib/jazzy/source_document.rb

Overview

Standalone markdown docs including index.html

Instance Attribute Summary collapse

Attributes inherited from SourceDeclaration

#abstract, #access_control_level, #children, #column, #declaration, #default_impl_abstract, #deprecated, #deprecation_message, #discussion, #end_line, #file, #from_protocol_extension, #generic_requirements, #inherited_types, #line, #mark, #modulename, #name, #nav_order, #objc_name, #other_language_declaration, #parameters, #parent_in_code, #parent_in_docs, #return, #start_line, #type, #type_usr, #typename, #unavailable, #unavailable_message, #url, #usr

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SourceDeclaration

#abstract_glob, #alternative_abstract, #alternative_abstract_file, #constrained_extension?, #display_declaration, #display_language, #display_other_language_declaration, #docs_filename, #filepath, #fully_qualified_name, #fully_qualified_name_regexp, #highlight_language, #inherited_types?, #mark_for_children, #namespace_ancestors, #namespace_path, #objc_category_name, #other_inherited_types?, #swift?, #swift_extension_objc_name, #swift_objc_extension?, #type_from_doc_module?, #usage_discouraged?

Constructor Details

#initializeSourceDocument

Returns a new instance of SourceDocument.



11
12
13
14
15
16
17
18
# File 'lib/jazzy/source_document.rb', line 11

def initialize
  super
  self.children = []
  self.parameters = []
  self.abstract = ''
  self.type = SourceDeclaration::Type.markdown
  self.mark = SourceMark.new
end

Instance Attribute Details

#overviewObject

Returns the value of attribute overview.



8
9
10
# File 'lib/jazzy/source_document.rb', line 8

def overview
  @overview
end

#readme_pathObject

Returns the value of attribute readme_path.



9
10
11
# File 'lib/jazzy/source_document.rb', line 9

def readme_path
  @readme_path
end

Class Method Details

.make_index(readme_path) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/jazzy/source_document.rb', line 20

def self.make_index(readme_path)
  SourceDocument.new.tap do |sd|
    sd.name = 'index'
    sd.url = sd.name + '.html'
    sd.readme_path = readme_path
  end
end

Instance Method Details

#configObject



36
37
38
# File 'lib/jazzy/source_document.rb', line 36

def config
  Config.instance
end

#config_readmeObject



53
54
55
# File 'lib/jazzy/source_document.rb', line 53

def config_readme
  readme_path.read if readme_path && readme_path.exist?
end

#content(source_module) ⇒ Object



44
45
46
47
# File 'lib/jazzy/source_document.rb', line 44

def content(source_module)
  return readme_content(source_module) if name == 'index'
  overview
end

#fallback_readmeObject



57
58
59
60
61
62
63
# File 'lib/jazzy/source_document.rb', line 57

def fallback_readme
  %w[README.md README.markdown README.mdown README].each do |potential_name|
    file = config.source_directory + potential_name
    return file.read if file.exist?
  end
  false
end

#generated_readme(source_module) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jazzy/source_document.rb', line 65

def generated_readme(source_module)
  if podspec = config.podspec
    ### License

    # <a href="#{license[:url]}">#{license[:license]}</a>
    <<-EOS
# #{podspec.name}

### #{podspec.summary}

#{podspec.description}

### Installation

```ruby
pod '#{podspec.name}'
```

### Authors

#{source_module.author_name}
EOS
  else
    <<-EOS
# #{source_module.name}

### Authors

#{source_module.author_name}
EOS
  end
end

#omit_content_from_parent?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/jazzy/source_document.rb', line 32

def omit_content_from_parent?
  true
end

#readme_content(source_module) ⇒ Object



49
50
51
# File 'lib/jazzy/source_document.rb', line 49

def readme_content(source_module)
  config_readme || fallback_readme || generated_readme(source_module)
end

#render_as_page?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/jazzy/source_document.rb', line 28

def render_as_page?
  true
end

#url_nameObject



40
41
42
# File 'lib/jazzy/source_document.rb', line 40

def url_name
  name.downcase.strip.tr(' ', '-').gsub(/[^[[:word:]]-]/, '')
end