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, #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?, #declaration_note, #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.



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



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

def config
  Config.instance
end

#config_readmeObject



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

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

#content(source_module) ⇒ Object



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

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

  overview
end

#fallback_readmeObject



60
61
62
63
64
65
66
# File 'lib/jazzy/source_document.rb', line 60

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



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
97
98
99
# File 'lib/jazzy/source_document.rb', line 68

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

    # <a href="#{license[:url]}">#{license[:license]}</a>
    "# \#{podspec.name}\n\n### \#{podspec.summary}\n\n\#{podspec.description}\n\n### Installation\n\n```ruby\npod '\#{podspec.name}'\n```\n\n### Authors\n\n\#{source_module.author_name}\n    README\n  else\n    <<-README\n# \#{source_module.name}\n\n### Authors\n\n\#{source_module.author_name}\n    README\n  end\nend\n"

#omit_content_from_parent?Boolean

Returns:

  • (Boolean)


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

def omit_content_from_parent?
  true
end

#readme_content(source_module) ⇒ Object



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

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

#render_as_page?Boolean

Returns:

  • (Boolean)


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

def render_as_page?
  true
end

#url_nameObject



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

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