Loading lib/jsduck/assets.rb +2 −2 Original line number Diff line number Diff line require 'jsduck/image_dir_set' require 'jsduck/img/dir_set' require 'jsduck/welcome' require 'jsduck/guides' require 'jsduck/videos' Loading Loading @@ -29,7 +29,7 @@ module JsDuck doc_formatter = DocFormatter.new(@opts) doc_formatter.relations = @relations @images = ImageDirSet.new(@opts.images, "images") @images = Img::DirSet.new(@opts.images, "images") @welcome = Welcome.create(@opts.welcome, doc_formatter) @guides = Guides.create(@opts.guides, doc_formatter, @opts) @videos = Videos.create(@opts.videos) Loading lib/jsduck/batch_formatter.rb +2 −2 Original line number Diff line number Diff line require 'jsduck/util/parallel' require 'jsduck/class_formatter' require 'jsduck/doc_formatter' require 'jsduck/image_dir_set' require 'jsduck/img/dir_set' require 'jsduck/logger' module JsDuck Loading Loading @@ -47,7 +47,7 @@ module JsDuck def self.create_class_formatter(relations, opts) doc_formatter = DocFormatter.new(opts) doc_formatter.relations = relations doc_formatter.images = ImageDirSet.new(opts.images, "images") doc_formatter.images = Img::DirSet.new(opts.images, "images") class_formatter = ClassFormatter.new(relations, doc_formatter) # Don't format types when exporting Loading lib/jsduck/class_formatter.rb +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ module JsDuck cls end # Access to the ImageDirSet object inside doc-formatter # Access to the Img::DirSet object inside doc-formatter def images @formatter.images end Loading lib/jsduck/guides.rb +2 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ require 'jsduck/util/null_object' require 'jsduck/logger' require 'jsduck/grouped_asset' require 'jsduck/util/html' require 'jsduck/image_dir' require 'jsduck/img/dir' require 'fileutils' module JsDuck Loading Loading @@ -60,7 +60,7 @@ module JsDuck begin @formatter.doc_context = {:filename => guide_file, :linenr => 0} @formatter.images = ImageDir.new(guide["url"], "guides/#{guide["name"]}") @formatter.images = Img::Dir.new(guide["url"], "guides/#{guide["name"]}") html = add_toc(guide, @formatter.format(Util::IO.read(guide_file))) # Report unused images (but ignore the icon files) Loading lib/jsduck/image_dir.rbdeleted 100644 → 0 +0 −92 Original line number Diff line number Diff line require 'dimensions' require 'jsduck/logger' module JsDuck # Looks up images from a directory. class ImageDir def initialize(full_path, relative_path) @full_path = full_path @relative_path = relative_path @images = {} end # Retrieves hash of information for a given relative image # filename. It will have the fields: # # - :filename - the same as the parameter of this method # - :full_path - actual path in the filesystem. # - :relative_path - relative path to be used inside <img> tag. # - :width - Image width # - :height - Image height # # When the image is not found, returns nil. def get(filename) img = scan_img(filename) if img @images[filename] = img end img end # Returns all used images. def all_used @images.values end # Print warnings about all unused images. def report_unused scan_for_unused_images.each {|img| warn_unused(img) } end private def scan_img(filename) full_path = File.join(@full_path, filename) if File.exists?(File.join(@full_path, filename)) img_record(filename) else nil end end # Scans directory for image files, building a hash of image files # found in that directory. def scan_for_unused_images unused = [] Dir[@full_path+"/**/*.{png,jpg,jpeg,gif}"].each do |path| filename = relative_path(@full_path, path) unused << img_record(filename) unless @images[filename] end unused end def warn_unused(img) Logger.warn(:image_unused, "Image not used.", img[:full_path]) end def img_record(filename) full_path = File.join(@full_path, filename) width, height = Dimensions.dimensions(full_path) return { :filename => filename, :relative_path => File.join(@relative_path, filename), :full_path => full_path, :width => width, :height => height, } end # Given a path to directory and a path to file, returns the path # to this file relative to the given dir. For example: # # base_path("/foo/bar", "/foo/bar/baz/img.jpg") --> "baz/img.jpg" # def relative_path(dir_path, file_path) file_path.slice(dir_path.length+1, file_path.length) end end end Loading
lib/jsduck/assets.rb +2 −2 Original line number Diff line number Diff line require 'jsduck/image_dir_set' require 'jsduck/img/dir_set' require 'jsduck/welcome' require 'jsduck/guides' require 'jsduck/videos' Loading Loading @@ -29,7 +29,7 @@ module JsDuck doc_formatter = DocFormatter.new(@opts) doc_formatter.relations = @relations @images = ImageDirSet.new(@opts.images, "images") @images = Img::DirSet.new(@opts.images, "images") @welcome = Welcome.create(@opts.welcome, doc_formatter) @guides = Guides.create(@opts.guides, doc_formatter, @opts) @videos = Videos.create(@opts.videos) Loading
lib/jsduck/batch_formatter.rb +2 −2 Original line number Diff line number Diff line require 'jsduck/util/parallel' require 'jsduck/class_formatter' require 'jsduck/doc_formatter' require 'jsduck/image_dir_set' require 'jsduck/img/dir_set' require 'jsduck/logger' module JsDuck Loading Loading @@ -47,7 +47,7 @@ module JsDuck def self.create_class_formatter(relations, opts) doc_formatter = DocFormatter.new(opts) doc_formatter.relations = relations doc_formatter.images = ImageDirSet.new(opts.images, "images") doc_formatter.images = Img::DirSet.new(opts.images, "images") class_formatter = ClassFormatter.new(relations, doc_formatter) # Don't format types when exporting Loading
lib/jsduck/class_formatter.rb +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ module JsDuck cls end # Access to the ImageDirSet object inside doc-formatter # Access to the Img::DirSet object inside doc-formatter def images @formatter.images end Loading
lib/jsduck/guides.rb +2 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ require 'jsduck/util/null_object' require 'jsduck/logger' require 'jsduck/grouped_asset' require 'jsduck/util/html' require 'jsduck/image_dir' require 'jsduck/img/dir' require 'fileutils' module JsDuck Loading Loading @@ -60,7 +60,7 @@ module JsDuck begin @formatter.doc_context = {:filename => guide_file, :linenr => 0} @formatter.images = ImageDir.new(guide["url"], "guides/#{guide["name"]}") @formatter.images = Img::Dir.new(guide["url"], "guides/#{guide["name"]}") html = add_toc(guide, @formatter.format(Util::IO.read(guide_file))) # Report unused images (but ignore the icon files) Loading
lib/jsduck/image_dir.rbdeleted 100644 → 0 +0 −92 Original line number Diff line number Diff line require 'dimensions' require 'jsduck/logger' module JsDuck # Looks up images from a directory. class ImageDir def initialize(full_path, relative_path) @full_path = full_path @relative_path = relative_path @images = {} end # Retrieves hash of information for a given relative image # filename. It will have the fields: # # - :filename - the same as the parameter of this method # - :full_path - actual path in the filesystem. # - :relative_path - relative path to be used inside <img> tag. # - :width - Image width # - :height - Image height # # When the image is not found, returns nil. def get(filename) img = scan_img(filename) if img @images[filename] = img end img end # Returns all used images. def all_used @images.values end # Print warnings about all unused images. def report_unused scan_for_unused_images.each {|img| warn_unused(img) } end private def scan_img(filename) full_path = File.join(@full_path, filename) if File.exists?(File.join(@full_path, filename)) img_record(filename) else nil end end # Scans directory for image files, building a hash of image files # found in that directory. def scan_for_unused_images unused = [] Dir[@full_path+"/**/*.{png,jpg,jpeg,gif}"].each do |path| filename = relative_path(@full_path, path) unused << img_record(filename) unless @images[filename] end unused end def warn_unused(img) Logger.warn(:image_unused, "Image not used.", img[:full_path]) end def img_record(filename) full_path = File.join(@full_path, filename) width, height = Dimensions.dimensions(full_path) return { :filename => filename, :relative_path => File.join(@relative_path, filename), :full_path => full_path, :width => width, :height => height, } end # Given a path to directory and a path to file, returns the path # to this file relative to the given dir. For example: # # base_path("/foo/bar", "/foo/bar/baz/img.jpg") --> "baz/img.jpg" # def relative_path(dir_path, file_path) file_path.slice(dir_path.length+1, file_path.length) end end end