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, #async, #children, #column, #declaration, #default_impl_abstract, #deprecated, #deprecation_message, #discussion, #doc_module_name, #end_line, #file, #from_protocol_extension, #generic_requirements, #inherited_types, #line, #mark, #module_name, #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, #ambiguous_module_name?, #constrained_extension?, #declaration_note, #display_declaration, #display_language, #display_other_language_declaration, #docs_filename, #docs_path, #extension_of_external_type?, #filepath, #fully_qualified_module_name, #fully_qualified_module_name_parts, #fully_qualified_name, #fully_qualified_name_regexp, #highlight_language, #index_names, #inherited_types?, #mark_for_children, #mark_undocumented?, #namespace_ancestors, #namespace_path, #need_doc_module_note?, #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.



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

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.



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

def overview
  @overview
end

#readme_pathObject

Returns the value of attribute readme_path.



11
12
13
# File 'lib/jazzy/source_document.rb', line 11

def readme_path
  @readme_path
end

Class Method Details

.make_index(readme_path) ⇒ Object



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

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



42
43
44
# File 'lib/jazzy/source_document.rb', line 42

def config
  Config.instance
end

#config_readmeObject



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

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

#content(source_module) ⇒ Object



50
51
52
53
54
# File 'lib/jazzy/source_document.rb', line 50

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

  overview
end

#fallback_readmeObject



64
65
66
67
68
69
70
# File 'lib/jazzy/source_document.rb', line 64

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



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
97
98
99
100
101
102
103
# File 'lib/jazzy/source_document.rb', line 72

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

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

### #{podspec.summary}

#{podspec.description}

### Installation

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

### Authors

#{source_module.author_name}
    README
  else
    <<-README
# #{source_module.readme_title}

### Authors

#{source_module.author_name}
    README
  end
end

#omit_content_from_parent?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/jazzy/source_document.rb', line 38

def omit_content_from_parent?
  true
end

#readme?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/jazzy/source_document.rb', line 30

def readme?
  url == 'index.html'
end

#readme_content(source_module) ⇒ Object



56
57
58
# File 'lib/jazzy/source_document.rb', line 56

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

#render_as_page?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/jazzy/source_document.rb', line 34

def render_as_page?
  true
end

#url_nameObject



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

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