Class: Pubba::Assets::Handler
- Inherits:
-
Object
- Object
- Pubba::Assets::Handler
- Extended by:
- Octopi
- Defined in:
- lib/pubba/assets/handler.rb
Direct Known Subclasses
Class Method Summary collapse
- .asset(file) ⇒ Object
-
.get_external_resource(url) ⇒ Object
Path, ext Path and extension of resource.
- .resources ⇒ Object
Instance Method Summary collapse
- #build(name, type, ext, urls) ⇒ Object
- #process(pattern, destination) ⇒ Object
-
#save_as(file) ⇒ Object
class block.
Class Method Details
.asset(file) ⇒ Object
13 14 15 |
# File 'lib/pubba/assets/handler.rb', line 13 def asset(file) raise NotImplementedError end |
.get_external_resource(url) ⇒ Object
Returns path, ext Path and extension of resource.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pubba/assets/handler.rb', line 18 def get_external_resource(url) path = '' ext = '' authenticated do parts = url.split(':') user = parts[1] repo = parts[2] tag = parts[3] file = parts[4] # file extension: .js ext = File.extname(file) # file name without extension basename = File.basename(file, ext) # subdir gitub/primedia subdir = File.join(parts[0], user) # github/repo/file path = File.join(subdir, basename) unless resources.include?(url) folder = (ext == '.css' ? Pubba.style_folder : Pubba.script_folder) # assets/js/github/repo/file out_path = File.join(Pubba.asset_folder, folder, subdir) FileUtils.mkdir_p(out_path) # assets/js/github/repo/file out_file = File.join(out_path, basename + ext) r = Repository.find(user: user, repo: repo) r..each do |t| if t.name == tag sha = t.sha begin blob = Blob.find(user: user, repo: repo, sha: sha, path: file) File.open(out_file, "w"){|f| f.write(blob.data) } break rescue Octopi::APIError => e puts "Error attempting to get: user: #{user}, repo: #{repo}, sha: #{sha}, path: #{file}" puts e. end end end resources << url end # resources include end return path, ext.split('.').last end |
.resources ⇒ Object
9 10 11 |
# File 'lib/pubba/assets/handler.rb', line 9 def resources @resources ||= [] end |
Instance Method Details
#build(name, type, ext, urls) ⇒ Object
82 83 84 |
# File 'lib/pubba/assets/handler.rb', line 82 def build(name, type, ext, urls) raise NotImplementedError end |
#process(pattern, destination) ⇒ Object
78 79 80 |
# File 'lib/pubba/assets/handler.rb', line 78 def process(pattern, destination) raise NotImplementedError end |
#save_as(file) ⇒ Object
class block
74 75 76 |
# File 'lib/pubba/assets/handler.rb', line 74 def save_as(file) raise NotImplementedError end |