gluey 0.2.3 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13441ecaca9c252379a8d03b9e759fb5331cd0db
4
- data.tar.gz: 7aeb4c4ac3185ce2fc80896e682b43363aaa2d5c
3
+ metadata.gz: 06efa92dcd6fd292dd71faf95ac07ce0dd921fdd
4
+ data.tar.gz: ea74e55f880c37e08b24a0002c8c243a5839016a
5
5
  SHA512:
6
- metadata.gz: 921626be9a86eabc724300b3edcb455a05cc585a7d520497ba1d2ed48b69db7336609ae3dd2e8b7edd2f08745a5f3d6ec5f7e73374124ef212aa7c993598fd75
7
- data.tar.gz: dac291204e1f5121badb9929f33d96fe1861add5b6a3cb185ee272a3ca7d2805234b1cf446de28fb168d2e8f242de1104a2d557959a4e6356d3a6b24513ef90a
6
+ metadata.gz: 39c68be866dbfc940bb6841075474b39735174cf76048992827ce8b870d045881bf83b46304f0cc0a62bf4b4f7623d23301235b47fdc9d78ebb20af08b54b9a7
7
+ data.tar.gz: 11c54bcc7c1c2875d54f2246c849216ef9a9c9889a6942881bf5d4188d9777a350e76372b52165c899b50cc57616ab427816615183941badfe9306d111e362d1
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .idea
@@ -25,5 +25,9 @@ module Gluey::Dependencies
25
25
  Dir[@dir_pattern]
26
26
  end
27
27
 
28
+ def mark
29
+ ''
30
+ end
31
+
28
32
  end
29
33
  end
@@ -19,6 +19,10 @@ module Gluey::Dependencies
19
19
  @dependencies.any?{|d| d.changed?} || @dir_dep.changed? || (File.mtime(@file).to_i != @mtime rescue true)
20
20
  end
21
21
 
22
+ def mark
23
+ @dependencies.map(&:mark).join
24
+ end
25
+
22
26
  def actualize
23
27
  # remove deleted files
24
28
  @dependencies.delete_if{|dep| !dep.exists? }
@@ -25,5 +25,9 @@ module Gluey::Dependencies
25
25
  @file == other.file
26
26
  end
27
27
 
28
+ def mark
29
+ File.mtime(@file).to_i.to_s
30
+ end
31
+
28
32
  end
29
33
  end
@@ -26,6 +26,10 @@ module Gluey::Dependencies
26
26
  @dependencies.any?{|d| d.changed?} || @dir_dep.changed? || (File.mtime(@file).to_i != @mtime rescue true)
27
27
  end
28
28
 
29
+ def mark
30
+ @dependencies.map(&:mark).join
31
+ end
32
+
29
33
  def actualize
30
34
  # remove deleted files
31
35
  @dependencies.delete_if{|dep| !dep.exists? }
@@ -16,7 +16,7 @@ module Gluey::Glues
16
16
 
17
17
  def read_base_file(file)
18
18
  raw_content = File.read(file)
19
- file[-4..-1]=='.erb' ? ERB.new(raw_content).result : raw_content
19
+ file[-4..-1]=='.erb' ? ERB.new(raw_content).result(@context.get_binding) : raw_content
20
20
  end
21
21
 
22
22
  end
@@ -24,6 +24,8 @@ module Gluey::Glues
24
24
  def self.load(name, *addons_names)
25
25
  require_relative name
26
26
  addons_names.flatten.each{|an| require_relative "#{name}/#{an}_addons" }
27
+ rescue LoadError => e
28
+ raise e.message
27
29
  end
28
30
 
29
31
  end
@@ -1,8 +1,9 @@
1
1
  require 'sass'
2
+ require_relative 'script'
2
3
  require_relative '../dependencies/single_file'
3
4
 
4
5
  module Gluey::Glues
5
- class Sass < Base
6
+ class Sass < Script
6
7
 
7
8
  def process(base_file, deps)
8
9
  opts = {
@@ -12,7 +13,7 @@ module Gluey::Glues
12
13
  filename: base_file,
13
14
  line_comments: true
14
15
  }
15
- engine = ::Sass::Engine.new(read_base_file(base_file), opts)
16
+ engine = ::Sass::Engine.new super(base_file, deps), opts
16
17
  output = engine.render
17
18
 
18
19
  engine.dependencies.each do |dependency|
@@ -3,8 +3,8 @@ require_relative '../dependencies/single_file'
3
3
  module Gluey::Glues
4
4
  class Script < Base
5
5
 
6
- PREFIXES = ['//'].map{|p| Regexp.escape(p)}
7
- DIRECTIVES_REGEXP = Regexp.compile "\\A(?:\\s*#{PREFIXES.map{|p| "(?:#{p}=.*\\n?)+"}.join '|'})+"
6
+ PREFIXES = ['//', '#'].map{|p| Regexp.escape(p)}
7
+ DIRECTIVES_REGEXP = Regexp.compile "\\A(?:\\s*#{PREFIXES.map{|p| "(?:#{p}>.*\\n?)+"}.join '|'})+"
8
8
 
9
9
  def process(base_file, deps)
10
10
  @script, @directives = strip_directives read_base_file(base_file)
@@ -46,7 +46,7 @@ module Gluey::Glues
46
46
  if directives
47
47
  script = $'
48
48
  directives = directives.split("\n").reject{|dir| dir.empty?}.map do |dir|
49
- dir.strip[/(?:#{PREFIXES.join '|'}=)\s*(.+)/, 1].split (' ')
49
+ dir.strip[/(?:#{PREFIXES.join '|'})>\s*(.+)/, 1].split (' ')
50
50
  end
51
51
  end
52
52
  return script, directives
@@ -2,7 +2,7 @@ require_relative 'exceptions/file_not_found'
2
2
 
3
3
  class Gluey::Material
4
4
 
5
- attr_reader :name, :glue
5
+ attr_reader :name, :glue, :paths, :items
6
6
  attr_accessor :asset, :file_extension, :public_dir
7
7
 
8
8
  def initialize(name, glue, context)
@@ -24,17 +24,20 @@ class Gluey::Material
24
24
  @items << declaration
25
25
  end
26
26
 
27
- def is_listed?(path, file=nil)
28
- @items.any? do |items_declaration|
29
- case items_declaration
30
- when String
31
- path == items_declaration
32
- when Regexp
33
- path =~ items_declaration
34
- when Proc
35
- items_declaration[path, file]
36
- end
37
- end
27
+ def is_listed?(path, file)
28
+ file[/\.(\w+)(?:\.erb)?$/, 1]==@file_extension &&
29
+ @items.any? do |items_declaration|
30
+ case items_declaration
31
+ when :all, :any
32
+ true
33
+ when String
34
+ path == items_declaration
35
+ when Regexp
36
+ path =~ items_declaration
37
+ when Proc
38
+ items_declaration[path, file]
39
+ end
40
+ end
38
41
  end
39
42
 
40
43
  def to_s
@@ -42,18 +45,18 @@ class Gluey::Material
42
45
  end
43
46
 
44
47
  def find_base_file(path)
45
- paths.each do |base_path|
48
+ full_paths.each do |base_path|
46
49
  p = "#{base_path}/#{path}.#{@file_extension}"; return p if File.exists? p
47
50
  p = "#{p}.erb"; return p if File.exists? p
48
51
  p = "#{base_path}/#{path}/index.#{@file_extension}"; return p if File.exists? p
49
52
  p = "#{p}.erb"; return p if File.exists? p
50
- end
53
+ end
51
54
  raise(::Gluey::FileNotFound.new "#{to_s} cannot find base file for #{path}")
52
55
  end
53
56
 
54
57
  def list_all_items
55
58
  list = []
56
- paths.map do |base_path|
59
+ full_paths.map do |base_path|
57
60
  glob_path = "#{base_path}/**/*.#{@file_extension}"
58
61
  files = Dir[glob_path] + Dir["#{glob_path}.erb"]
59
62
  files.select do |file|
@@ -67,7 +70,7 @@ class Gluey::Material
67
70
 
68
71
  private
69
72
 
70
- def paths
73
+ def full_paths
71
74
  @paths.map{|p| "#{@context.root_path}/#{p}"}
72
75
  end
73
76
 
data/lib/gluey/url.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Gluey::Url
2
+
3
+ attr_accessor :base_url
4
+
5
+ def asset_url(material, path, mark=false)
6
+ "#{base_url}/#{material}/#{real_path material, path, mark}"
7
+ end
8
+
9
+ end
data/lib/gluey/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gluey
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.7'
3
3
  end
@@ -1,8 +1,10 @@
1
1
  require_relative '../gluey'
2
+ require_relative 'url'
2
3
  require_relative 'exceptions/item_not_listed'
3
4
  require 'json'
4
5
 
5
6
  class Gluey::Warehouse
7
+ include Gluey::Url
6
8
 
7
9
  attr_reader :assets
8
10
 
@@ -11,7 +13,7 @@ class Gluey::Warehouse
11
13
  read_listing
12
14
  end
13
15
 
14
- def real_path(asset_type, path)
16
+ def real_path(asset_type, path, mark=nil)
15
17
  listing = @assets[asset_type]
16
18
  unless listing
17
19
  raise ::Gluey::ItemNotListed.new("Asset type #{asset_type} is not defined! (listing file problem?)")
@@ -38,7 +40,7 @@ class Gluey::Warehouse
38
40
  def write_listing(workshop)
39
41
  @assets = workshop.materials.values.inject({}) do |listing, material|
40
42
  list = material.list_all_items.inject({}) do |h, path|
41
- h[path] = workshop.real_path material.name, path
43
+ h[path] = workshop.real_path material.name, path, true
42
44
  h
43
45
  end
44
46
  listing[material.name.to_sym] = list
@@ -1,4 +1,6 @@
1
+ require 'digest'
1
2
  require_relative '../gluey'
3
+ require_relative 'url'
2
4
 
3
5
  require_relative 'exceptions/item_not_listed'
4
6
 
@@ -6,8 +8,10 @@ require_relative 'material'
6
8
  require_relative 'glues/base'
7
9
 
8
10
  class Gluey::Workshop
11
+ include Gluey::Url
9
12
 
10
13
  attr_reader :root_path, :tmp_path, :materials, :cache
14
+ attr_accessor :base_url
11
15
 
12
16
  def initialize(root, tmp_dir='tmp/gluey')
13
17
  @root_path = root
@@ -20,12 +24,13 @@ class Gluey::Workshop
20
24
  def register_material(name, glue=::Gluey::Glues::Base, &block)
21
25
  name = name.to_sym
22
26
  material = ::Gluey::Material.new name, glue, self, &block
27
+ material.items << :any if material.items.empty?
23
28
  @materials[name] = material
24
29
  end
25
30
 
26
31
  def fetch_file(material, path)
27
32
  # check cache
28
- cache_key = "lump:#{material}:#{path}"
33
+ cache_key = chache_asset_key material, path
29
34
  file, dependencies = @cache[cache_key]
30
35
  if file && File.exists?(file) && !dependencies.any?{|d| d.changed?}
31
36
  return file
@@ -46,19 +51,37 @@ class Gluey::Workshop
46
51
  file
47
52
  end
48
53
 
49
- def real_path(material, path)
54
+ def real_path(material, path, digest_mark=false)
50
55
  material = @materials[material.to_sym]
51
56
  file = material.find_base_file path
52
57
  unless material.is_listed? path, file
53
58
  raise ::Gluey::ItemNotListed.new("#{material.to_s} doesn't have enlisted item #{path} (file=#{file}).")
54
59
  end
55
- "#{path}.#{File.mtime(file).to_i}.#{material.asset}"
60
+ if digest_mark
61
+ fetch_file material.name, path
62
+ cache_key = chache_asset_key material.name, path
63
+ file, dependencies = @cache[cache_key]
64
+ digested_mark = Digest::MD5.new.digest dependencies.map(&:mark).join
65
+ "#{path}.#{Digest.hexencode digested_mark}.#{material.asset}"
66
+ else
67
+ "#{path}.#{material.asset}"
68
+ end
56
69
  end
57
70
 
58
71
  def try_real_path(path)
59
- path.match /^(.+)\.\d+\.(\w+)$/ do |m|
72
+ path.match /^(.+)\.(?:[a-f0-9]{32}\.)(\w+)$/ do |m|
60
73
  yield m[1], m[2]
61
74
  end
62
75
  end
63
76
 
77
+ def get_binding
78
+ binding
79
+ end
80
+
81
+ private
82
+
83
+ def chache_asset_key(material, path)
84
+ "lump:#{material}:#{path}"
85
+ end
86
+
64
87
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gluey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - doooby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-02 00:00:00.000000000 Z
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,6 +67,7 @@ files:
67
67
  - lib/gluey/material.rb
68
68
  - lib/gluey/tools/local_build.rb
69
69
  - lib/gluey/tools/tools.rb
70
+ - lib/gluey/url.rb
70
71
  - lib/gluey/version.rb
71
72
  - lib/gluey/warehouse.rb
72
73
  - lib/gluey/workshop.rb