Class: SmallVictories::SiteFile
- Inherits:
-
Object
- Object
- SmallVictories::SiteFile
- Defined in:
- lib/smallvictories/site_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #asset? ⇒ Boolean
- #audio? ⇒ Boolean
- #css? ⇒ Boolean
- #downloadable? ⇒ Boolean
- #extension ⇒ Object
- #file ⇒ Object
- #file_type ⇒ Object
- #html? ⇒ Boolean
- #image? ⇒ Boolean
-
#initialize(path) ⇒ SiteFile
constructor
A new instance of SiteFile.
- #js? ⇒ Boolean
- #markdown? ⇒ Boolean
- #media_asset? ⇒ Boolean
- #pdf? ⇒ Boolean
- #read ⇒ Object
- #render ⇒ Object
- #text? ⇒ Boolean
- #text_based_file? ⇒ Boolean
- #video? ⇒ Boolean
- #webloc? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ SiteFile
Returns a new instance of SiteFile.
24 25 26 |
# File 'lib/smallvictories/site_file.rb', line 24 def initialize path @path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/smallvictories/site_file.rb', line 3 def path @path end |
Class Method Details
.files_hash(folder_path = SmallVictories::Server::WEB_ROOT) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/smallvictories/site_file.rb', line 5 def self.files_hash folder_path=SmallVictories::Server::WEB_ROOT hash = {} Dir.glob(File.join(folder_path, '*')) do |path| next if path == '.' or path == '..' file = SiteFile.new path key = path.gsub(folder_path, '').gsub(/^\//, '').gsub('/', '.') key = key.gsub(/\.#{file.extension}$/, '') if Dir.exists?(path) hash[key] = SiteFile.files_hash(path) else hash[key] = file.downloadable? ? path : file.read end end hash end |
Instance Method Details
#asset? ⇒ Boolean
44 45 46 |
# File 'lib/smallvictories/site_file.rb', line 44 def asset? audio? or image? or video? or css? or js? end |
#audio? ⇒ Boolean
52 53 54 |
# File 'lib/smallvictories/site_file.rb', line 52 def audio? file_type =~ /audio/ ? true : false end |
#css? ⇒ Boolean
56 57 58 |
# File 'lib/smallvictories/site_file.rb', line 56 def css? extension == 'css' end |
#downloadable? ⇒ Boolean
60 61 62 |
# File 'lib/smallvictories/site_file.rb', line 60 def downloadable? asset? || pdf? end |
#extension ⇒ Object
28 29 30 |
# File 'lib/smallvictories/site_file.rb', line 28 def extension File.extname(path).gsub(/^./,'') end |
#file ⇒ Object
32 33 34 |
# File 'lib/smallvictories/site_file.rb', line 32 def file File.open(path) end |
#file_type ⇒ Object
40 41 42 |
# File 'lib/smallvictories/site_file.rb', line 40 def file_type MIME::Types.type_for('css') end |
#html? ⇒ Boolean
84 85 86 |
# File 'lib/smallvictories/site_file.rb', line 84 def html? extension == 'html' end |
#image? ⇒ Boolean
64 65 66 |
# File 'lib/smallvictories/site_file.rb', line 64 def image? file_type =~ /image/ ? true : false end |
#js? ⇒ Boolean
68 69 70 |
# File 'lib/smallvictories/site_file.rb', line 68 def js? extension == 'js' end |
#markdown? ⇒ Boolean
88 89 90 |
# File 'lib/smallvictories/site_file.rb', line 88 def markdown? extension == 'md' end |
#media_asset? ⇒ Boolean
48 49 50 |
# File 'lib/smallvictories/site_file.rb', line 48 def media_asset? audio? or image? or video? end |
#pdf? ⇒ Boolean
96 97 98 |
# File 'lib/smallvictories/site_file.rb', line 96 def pdf? extension == 'pdf' end |
#read ⇒ Object
36 37 38 |
# File 'lib/smallvictories/site_file.rb', line 36 def read file.read end |
#render ⇒ Object
76 77 78 |
# File 'lib/smallvictories/site_file.rb', line 76 def render read end |
#text? ⇒ Boolean
80 81 82 |
# File 'lib/smallvictories/site_file.rb', line 80 def text? extension == 'txt' end |
#text_based_file? ⇒ Boolean
100 101 102 |
# File 'lib/smallvictories/site_file.rb', line 100 def text_based_file? markdown? || text? || html? || webloc? || pdf? end |
#video? ⇒ Boolean
72 73 74 |
# File 'lib/smallvictories/site_file.rb', line 72 def video? file_type =~ /video/ ? true : false end |
#webloc? ⇒ Boolean
92 93 94 |
# File 'lib/smallvictories/site_file.rb', line 92 def webloc? extension == 'webloc' || extension.downcase == 'url' end |