Class: Pubba::Assets::Handler

Inherits:
Object
  • Object
show all
Extended by:
Octopi
Defined in:
lib/pubba/assets/handler.rb

Direct Known Subclasses

SprocketsHandler

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.asset(file) ⇒ Object

Raises:

  • (NotImplementedError)


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.

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.tags.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.message
          end
        end
      end

      resources << url
    end # resources include
  end

  return path, ext.split('.').last
end

.resourcesObject



9
10
11
# File 'lib/pubba/assets/handler.rb', line 9

def resources
  @resources ||= []
end

Instance Method Details

#build(name, type, ext, urls) ⇒ Object

Raises:

  • (NotImplementedError)


82
83
84
# File 'lib/pubba/assets/handler.rb', line 82

def build(name, type, ext, urls)
  raise NotImplementedError
end

#process(pattern, destination) ⇒ Object

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/pubba/assets/handler.rb', line 78

def process(pattern, destination)
  raise NotImplementedError
end

#save_as(file) ⇒ Object

class block

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/pubba/assets/handler.rb', line 74

def save_as(file)
  raise NotImplementedError
end