Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer-dsl-opal/ext/file.rb

Constant Summary collapse

REGEXP_DIR_FILE =
/\(dir\)|\(file\)/

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.image_pathsObject

Returns the value of attribute image_paths.



28
29
30
# File 'lib/glimmer-dsl-opal/ext/file.rb', line 28

def image_paths
  @image_paths
end

Class Method Details

.expand_path(path, base = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/glimmer-dsl-opal/ext/file.rb', line 38

def expand_path(path, base=nil)
  get_image_paths unless image_paths
  path = expand_path_without_glimmer(path, base) if base
  path_include_dir_or_file = !!path.match(REGEXP_DIR_FILE)
  essential_path = path.split('(dir)').last.split('(file)').last.split('../').last.split('./').last
  image_paths.detect do |image_path|
    image_path.include?(essential_path)
  end
end

.expand_path_without_glimmerObject

Include special processing for images that matches them against a list of available image paths from the server to convert to web paths.



37
# File 'lib/glimmer-dsl-opal/ext/file.rb', line 37

alias expand_path_without_glimmer expand_path

.get_image_pathsObject



48
49
50
51
# File 'lib/glimmer-dsl-opal/ext/file.rb', line 48

def get_image_paths
  image_paths_json = Net::HTTP.get(`window.location.origin`, "/glimmer/image_paths.json")
  self.image_paths = JSON.parse(image_paths_json)
end

.read(*args, &block) ⇒ Object



30
31
32
33
# File 'lib/glimmer-dsl-opal/ext/file.rb', line 30

def read(*args, &block)
  # TODO implement via asset downloads in the future
  # No Op in Opal
end