class DevTraining::Readme
Class representing the “README” file in the training repository. It is responsible for rendering a template file through Tilt and creating the file in the Training
repository.
Constants
- FILENAME
-
Name of the file in the repository
Public Class Methods
Source
# File lib/dev_training/readme.rb, line 22 def initialize(filename, client, repo) @template = Tilt.new(filename, trim: '-') @client = client @repo = repo end
Arguments:
-
filename
: The path to a template file or a type that Tilt knows how to render -
client
: AnOctokit::Client
-
repo
: ADevTraining::Repository
that will hold the README
Public Instance Methods
Source
# File lib/dev_training/readme.rb, line 33 def content @template.render(self) end
The rendered content of the README template. Note that the template is passed self
with it’s call to render, which means that you have access to instance variables and (even private
) methods of this instance within the template.
Source
# File lib/dev_training/readme.rb, line 44 def resource @resource ||= readme || create_readme end
The Sawyer::Resource
representing the contents of the readme if found, or the contents and commit information if not found and created with content
Note that updating a file in a repository is a much more involved process; we don’t attempt it. If any README (in any format) exists in the repository, we let it be.
Template Helper Methods
↑ topProtected Instance Methods
Source
# File lib/dev_training/readme.rb, line 60 def repo_relative(path) base = URI.parse(@repo.resource.html_url) URI.join(base, "#{base.path}/#{path}") end
Constructs an absolute URL relative to the repository’s URL
Source
# File lib/dev_training/readme.rb, line 68 def user_name @client.user.name || @client.user.login end
The user’s “real” name if available, or their login name as a fallback (many folks leave their name blank)