Class: Jekyll::RemoteTheme::Theme
- Inherits:
-
Theme
- Object
- Theme
- Jekyll::RemoteTheme::Theme
- Defined in:
- lib/jekyll-remote-theme/theme.rb
Constant Summary collapse
- OWNER_REGEX =
%r!(?<owner>[a-z0-9\-]+)!i.freeze
- NAME_REGEX =
%r!(?<name>[a-z0-9\._\-]+)!i.freeze
- REF_REGEX =
May be a branch, tag, commit, or “latest”
%r!@(?<ref>[a-z0-9\._\-]+)!i.freeze
- THEME_REGEX =
%r!\A#{OWNER_REGEX}/#{NAME_REGEX}(?:#{REF_REGEX})?\z!i.freeze
Instance Method Summary collapse
- #git_ref ⇒ Object
- #host ⇒ Object
-
#initialize(raw_theme) ⇒ Theme
constructor
Initializes a new Jekyll::RemoteTheme::Theme.
- #inspect ⇒ Object
- #local_theme? ⇒ Boolean
- #name ⇒ Object
- #name_with_owner ⇒ Object (also: #nwo)
- #owner ⇒ Object
- #root ⇒ Object
- #scheme ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(raw_theme) ⇒ Theme
Initializes a new Jekyll::RemoteTheme::Theme
raw_theme can be in the form of:
-
owner/theme-name - a GitHub owner + theme-name string
-
owner/theme-name@git_ref - a GitHub owner + theme-name + Git ref string
-
http://github.<yourEnterprise>.com/owner/theme-name
-
An enterprise GitHub instance + a GitHub owner + a theme-name string
-
http://github.<yourEnterprise>.com/owner/theme-name@git_ref
-
An enterprise GitHub instance + a GitHub owner + a theme-name + Git ref string
-
/absolute/path/to/theme - an absolute local file path
-
../relative/path/to/theme - a relative local file path
-
~/path/to/theme - a home directory relative path
24 25 26 27 28 29 |
# File 'lib/jekyll-remote-theme/theme.rb', line 24 def initialize(raw_theme) original_theme = raw_theme.to_s.strip local_path = looks_like_local_path?(original_theme) @raw_theme = local_path ? original_theme : original_theme.downcase super(@raw_theme) end |
Instance Method Details
#git_ref ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/jekyll-remote-theme/theme.rb', line 62 def git_ref return "HEAD" if local_theme? parsed_ref = theme_parts[:ref] return "HEAD" unless parsed_ref return resolve_latest_release if parsed_ref == "latest" parsed_ref end |
#host ⇒ Object
43 44 45 |
# File 'lib/jekyll-remote-theme/theme.rb', line 43 def host uri&.host end |
#inspect ⇒ Object
76 77 78 79 |
# File 'lib/jekyll-remote-theme/theme.rb', line 76 def inspect "#<Jekyll::RemoteTheme::Theme host=\"#{host}\" owner=\"#{owner}\" name=\"#{name}\"" \ " ref=\"#{git_ref}\" root=\"#{root}\">" end |
#local_theme? ⇒ Boolean
81 82 83 |
# File 'lib/jekyll-remote-theme/theme.rb', line 81 def local_theme? @local_theme ||= looks_like_local_path?(@raw_theme) end |
#name ⇒ Object
31 32 33 34 35 |
# File 'lib/jekyll-remote-theme/theme.rb', line 31 def name return File.basename() if local_theme? theme_parts[:name] end |
#name_with_owner ⇒ Object Also known as: nwo
51 52 53 |
# File 'lib/jekyll-remote-theme/theme.rb', line 51 def name_with_owner [owner, name].join("/") end |
#owner ⇒ Object
37 38 39 40 41 |
# File 'lib/jekyll-remote-theme/theme.rb', line 37 def owner return "local" if local_theme? theme_parts[:owner] end |
#root ⇒ Object
72 73 74 |
# File 'lib/jekyll-remote-theme/theme.rb', line 72 def root @root ||= local_theme? ? : File.realpath(Dir.mktmpdir(TEMP_PREFIX)) end |
#scheme ⇒ Object
47 48 49 |
# File 'lib/jekyll-remote-theme/theme.rb', line 47 def scheme uri&.scheme end |
#valid? ⇒ Boolean
56 57 58 59 60 |
# File 'lib/jekyll-remote-theme/theme.rb', line 56 def valid? return local_path_valid? if local_theme? remote_theme_valid? end |