Class: Jekyll::RemoteTheme::Theme

Inherits:
Theme
  • Object
show all
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

Constructor Details

#initialize(raw_theme) ⇒ Theme

Initializes a new Jekyll::RemoteTheme::Theme

raw_theme can be in the form of:

  1. owner/theme-name - a GitHub owner + theme-name string

  2. owner/theme-name@git_ref - a GitHub owner + theme-name + Git ref string

  3. http://github.<yourEnterprise>.com/owner/theme-name

  • An enterprise GitHub instance + a GitHub owner + a theme-name string

  1. http://github.<yourEnterprise>.com/owner/theme-name@git_ref

  • An enterprise GitHub instance + a GitHub owner + a theme-name + Git ref string

  1. /absolute/path/to/theme - an absolute local file path

  2. ../relative/path/to/theme - a relative local file path

  3. ~/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_refObject



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

#hostObject



43
44
45
# File 'lib/jekyll-remote-theme/theme.rb', line 43

def host
  uri&.host
end

#inspectObject



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

Returns:

  • (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

#nameObject



31
32
33
34
35
# File 'lib/jekyll-remote-theme/theme.rb', line 31

def name
  return File.basename(expanded_local_path) if local_theme?

  theme_parts[:name]
end

#name_with_ownerObject Also known as: nwo



51
52
53
# File 'lib/jekyll-remote-theme/theme.rb', line 51

def name_with_owner
  [owner, name].join("/")
end

#ownerObject



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

#rootObject



72
73
74
# File 'lib/jekyll-remote-theme/theme.rb', line 72

def root
  @root ||= local_theme? ? expanded_local_path : File.realpath(Dir.mktmpdir(TEMP_PREFIX))
end

#schemeObject



47
48
49
# File 'lib/jekyll-remote-theme/theme.rb', line 47

def scheme
  uri&.scheme
end

#valid?Boolean

Returns:

  • (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