Class: Giblish::ResourcePaths

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/resourcepaths.rb

Overview

Provides relevant paths for layout resources based on the given options

Constant Summary collapse

FORMAT_CONVENTIONS =
{
  "html5" => ".css",
  "html" => ".css",
  "pdf" => ".yml",
  "web-pdf" => ".css"
}
FONT_REGEX =
/.*\.(ttf)|(TTF)$/
WEB_ASSET_TOP_BASENAME =
Pathname.new("web_assets")
IDX_ERB_TEMPLATE_BASENAME =
"idx_template.erb"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd_opts) ⇒ ResourcePaths

attributes:

.format        required
.resource_dir  required
.dst_dir       required
.style_name    optional
.idx_erb_basename    optional

Raises:

  • (OptionParser::InvalidArgument)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/giblish/resourcepaths.rb', line 49

def initialize(cmd_opts)
  raise OptionParser::InvalidArgument, "Unsupported format: #{cmd_opts.format}" unless FORMAT_CONVENTIONS.key?(cmd_opts.format)

  init_to_default(cmd_opts)

  return if @src_resource_dir_abs.nil?

  # Tweak paths based on the content of a given resource dir
  file_tree = PathTree.build_from_fs(@src_resource_dir_abs)

  @src_style_path_rel = find_style_file(file_tree, cmd_opts.format, cmd_opts.style_name)
  @src_style_path_abs = @src_resource_dir_abs / @src_style_path_rel if @src_style_path_rel
  @dst_style_path_rel = WEB_ASSET_TOP_BASENAME / @src_style_path_rel if @src_style_path_rel

  @font_dirs_abs = find_font_dirs(file_tree)

  erb_template = find_unique_file(file_tree, IDX_ERB_TEMPLATE_BASENAME)
  if erb_template
    @idx_erb_template_rel = erb_template
    @idx_erb_template_abs = @src_resource_dir_abs / @idx_erb_template_rel
  end
end

Instance Attribute Details

#dst_style_path_relObject (readonly)

the relative path from the dst top dir to the copied style file (if it would be copied)



29
30
31
# File 'lib/giblish/resourcepaths.rb', line 29

def dst_style_path_rel
  @dst_style_path_rel
end

#dst_webasset_dir_absObject (readonly)

the abs path to the top of the destination dir for resources



32
33
34
# File 'lib/giblish/resourcepaths.rb', line 32

def dst_webasset_dir_abs
  @dst_webasset_dir_abs
end

#font_dirs_absObject (readonly)

a set with all dirs containing ttf files, paths are relative to resource area top



26
27
28
# File 'lib/giblish/resourcepaths.rb', line 26

def font_dirs_abs
  @font_dirs_abs
end

#idx_erb_template_absObject (readonly)

the absolute path to the erb template for index generation



41
42
43
# File 'lib/giblish/resourcepaths.rb', line 41

def idx_erb_template_abs
  @idx_erb_template_abs
end

#idx_erb_template_relObject (readonly)

the relative path to the erb template for index generation



38
39
40
# File 'lib/giblish/resourcepaths.rb', line 38

def idx_erb_template_rel
  @idx_erb_template_rel
end

#src_resource_dir_absObject (readonly)

the abs path to the top of the source dir for resources



35
36
37
# File 'lib/giblish/resourcepaths.rb', line 35

def src_resource_dir_abs
  @src_resource_dir_abs
end

#src_style_path_absObject (readonly)

the absolute path from the top of the resource area to the style file



23
24
25
# File 'lib/giblish/resourcepaths.rb', line 23

def src_style_path_abs
  @src_style_path_abs
end

#src_style_path_relObject (readonly)

the relative path from the top of the resource area to the style file



19
20
21
# File 'lib/giblish/resourcepaths.rb', line 19

def src_style_path_rel
  @src_style_path_rel
end