Class: Giblish::ResourcePaths
- Inherits:
-
Object
- Object
- Giblish::ResourcePaths
- 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
-
#dst_style_path_rel ⇒ Object
readonly
the relative path from the dst top dir to the copied style file (if it would be copied).
-
#dst_webasset_dir_abs ⇒ Object
readonly
the abs path to the top of the destination dir for resources.
-
#font_dirs_abs ⇒ Object
readonly
a set with all dirs containing ttf files, paths are relative to resource area top.
-
#idx_erb_template_abs ⇒ Object
readonly
the absolute path to the erb template for index generation.
-
#idx_erb_template_rel ⇒ Object
readonly
the relative path to the erb template for index generation.
-
#src_resource_dir_abs ⇒ Object
readonly
the abs path to the top of the source dir for resources.
-
#src_style_path_abs ⇒ Object
readonly
the absolute path from the top of the resource area to the style file.
-
#src_style_path_rel ⇒ Object
readonly
the relative path from the top of the resource area to the style file.
Instance Method Summary collapse
-
#initialize(cmd_opts) ⇒ ResourcePaths
constructor
attributes: .format required .resource_dir required .dst_dir required .style_name optional .idx_erb_basename optional.
Constructor Details
#initialize(cmd_opts) ⇒ ResourcePaths
attributes:
.format required
.resource_dir required
.dst_dir required
.style_name optional
.idx_erb_basename optional
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_rel ⇒ Object (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_abs ⇒ Object (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_abs ⇒ Object (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_abs ⇒ Object (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_rel ⇒ Object (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_abs ⇒ Object (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_abs ⇒ Object (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_rel ⇒ Object (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 |