web_blocks 2.0.5.alpha → 2.1.0.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/web_blocks/facade/directory_name_block.rb +49 -0
- data/lib/web_blocks/facade/external_component_block.rb +2 -2
- data/lib/web_blocks/facade/file_name_block.rb +13 -13
- data/lib/web_blocks/facade/recursive_file_names_block.rb +3 -1
- data/lib/web_blocks/facade/registration_scope.rb +25 -0
- data/lib/web_blocks/structure/block_core.rb +115 -7
- data/lib/web_blocks/structure/framework.rb +48 -15
- data/lib/web_blocks/thor/base/prepare_blocks.rb +21 -0
- data/lib/web_blocks/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54d667a2922c092ca505ebba10d8688f133adb66
|
4
|
+
data.tar.gz: 34dab65bd98305bd50533cdab2802d660b7b89dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9a51b7252410a7f74c2ce82c1ba177612cae219a07a42ffec9f378447b2e7603c996e6b2add43c184689ff035dad76c8ccdbd1744cbdd459789f1e51aafd00
|
7
|
+
data.tar.gz: 8caf18f9cd3335c24e1f10fc240b768a73bf5c63277fc101954256b282a53ab7281d1f7e45dd83d4c3682ea56eaf6782fe6f07ccb08e3a02378b3122b0fca51a
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'web_blocks/facade/base'
|
3
|
+
|
4
|
+
module WebBlocks
|
5
|
+
module Facade
|
6
|
+
class DirectoryNameBlock < Base
|
7
|
+
|
8
|
+
def handle name, attributes = {}, &block
|
9
|
+
|
10
|
+
this = self
|
11
|
+
|
12
|
+
attributes[:path] = name unless attributes.has_key? :path
|
13
|
+
|
14
|
+
block_was_given = block_given?
|
15
|
+
|
16
|
+
this.context.block name, attributes do |directory_block|
|
17
|
+
|
18
|
+
directory_path = directory_block.resolved_path
|
19
|
+
js_file_names = Set.new
|
20
|
+
scss_file_names = Set.new
|
21
|
+
|
22
|
+
Dir.entries(directory_path).each do |name|
|
23
|
+
next if name == '.' or name == '..'
|
24
|
+
path = "#{directory_path}/#{name}"
|
25
|
+
if File.file? path
|
26
|
+
segs = name.split('.')
|
27
|
+
ext = segs.pop
|
28
|
+
if ext == 'css'
|
29
|
+
scss_file_names << "#{segs.join('.')}.css"
|
30
|
+
elsif ext == 'js'
|
31
|
+
js_file_names << "#{segs.join('.')}.js"
|
32
|
+
elsif ext == 'scss'
|
33
|
+
scss_file_names << segs.join('.').gsub(/^_/, '')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
js_file_names.each { |name| directory_block.js_file name }
|
39
|
+
scss_file_names.each { |name| directory_block.scss_file name }
|
40
|
+
|
41
|
+
directory_block.instance_eval &block if block_was_given
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -7,9 +7,9 @@ module WebBlocks
|
|
7
7
|
|
8
8
|
def handle name, attributes = {}, &block
|
9
9
|
if attributes.has_key?(:path)
|
10
|
-
attributes[:path] = "bower_components/#{name}/#{attributes[:path]}"
|
10
|
+
attributes[:path] = "#{context.framework.resolved_path}/bower_components/#{name}/#{attributes[:path]}"
|
11
11
|
else
|
12
|
-
attributes[:path] = "bower_components/#{name}"
|
12
|
+
attributes[:path] = "#{context.framework.resolved_path}/bower_components/#{name}"
|
13
13
|
end
|
14
14
|
context.block name, attributes, &block
|
15
15
|
end
|
@@ -4,17 +4,6 @@ module WebBlocks
|
|
4
4
|
module Facade
|
5
5
|
class FileNameBlock < Base
|
6
6
|
|
7
|
-
attr_reader :types
|
8
|
-
|
9
|
-
def initialize context
|
10
|
-
super context
|
11
|
-
@types = {
|
12
|
-
'css' => :scss_file,
|
13
|
-
'js' => :js_file,
|
14
|
-
'scss' => :scss_file
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
7
|
def handle name, attributes = {}, &block
|
19
8
|
|
20
9
|
this = self
|
@@ -22,10 +11,21 @@ module WebBlocks
|
|
22
11
|
block_was_given = block_given?
|
23
12
|
|
24
13
|
this.context.block name, attributes do |block_entity|
|
25
|
-
|
26
|
-
|
14
|
+
|
15
|
+
if File.exists? "#{block_entity.resolved_path}/#{name}.css"
|
16
|
+
block_entity.scss_file "#{name}.css"
|
17
|
+
end
|
18
|
+
|
19
|
+
if File.exists? "#{block_entity.resolved_path}/#{name}.js"
|
20
|
+
block_entity.js_file "#{name}.js"
|
27
21
|
end
|
22
|
+
|
23
|
+
if File.exists?("#{block_entity.resolved_path}/#{name}.scss") or File.exists?("#{block_entity.resolved_path}/_#{name}.scss")
|
24
|
+
block_entity.scss_file name
|
25
|
+
end
|
26
|
+
|
28
27
|
block_entity.instance_eval &block if block_was_given
|
28
|
+
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -29,8 +29,10 @@ module WebBlocks
|
|
29
29
|
else
|
30
30
|
segs = name.split('.')
|
31
31
|
ext = segs.pop
|
32
|
-
if
|
32
|
+
if ext == 'css' or ext == 'js'
|
33
33
|
file_names << segs.join('.')
|
34
|
+
elsif ext == 'scss'
|
35
|
+
file_names << segs.join('.').gsub(/^_/, '')
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'web_blocks/facade/base'
|
2
|
+
|
3
|
+
module WebBlocks
|
4
|
+
module Facade
|
5
|
+
class RegistrationScope < Base
|
6
|
+
|
7
|
+
def initialize context
|
8
|
+
super context
|
9
|
+
@@registration_scope = nil unless defined? @@registration_scope
|
10
|
+
end
|
11
|
+
|
12
|
+
def handle command = nil, data = {}, &block
|
13
|
+
case command
|
14
|
+
when :set
|
15
|
+
@@registration_scope = data
|
16
|
+
when :unset
|
17
|
+
@@registration_scope = nil
|
18
|
+
end
|
19
|
+
@@registration_scope
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'extend_method'
|
2
|
+
require 'web_blocks/facade/block'
|
1
3
|
require 'web_blocks/framework'
|
2
4
|
require 'web_blocks/structure/tree/node'
|
3
5
|
require 'web_blocks/structure/attribute/dependency'
|
@@ -9,6 +11,10 @@ module WebBlocks
|
|
9
11
|
module Structure
|
10
12
|
class BlockCore < ::WebBlocks::Structure::Tree::Node
|
11
13
|
|
14
|
+
class << self
|
15
|
+
include ExtendMethod
|
16
|
+
end
|
17
|
+
|
12
18
|
include WebBlocks::Framework
|
13
19
|
|
14
20
|
include WebBlocks::Structure::Attribute::Dependency
|
@@ -16,8 +22,12 @@ module WebBlocks
|
|
16
22
|
include WebBlocks::Structure::Attribute::ReverseDependency
|
17
23
|
include WebBlocks::Structure::Attribute::ReverseLooseDependency
|
18
24
|
|
25
|
+
##
|
26
|
+
# Methods supporting extending the block DSL with facades for non-primitive blocks
|
27
|
+
#
|
28
|
+
|
19
29
|
def register_facade name, handler
|
20
|
-
@facade_map = {} unless defined? @facade_map
|
30
|
+
@facade_map = {} unless (defined?(@facade_map) and @facade_map)
|
21
31
|
@facade_map[name.to_sym] = handler
|
22
32
|
end
|
23
33
|
|
@@ -65,17 +75,115 @@ module WebBlocks
|
|
65
75
|
handler.handle *arguments, &block
|
66
76
|
end
|
67
77
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
78
|
+
##
|
79
|
+
# Methods supporting pathing enabled by WebBlocks::Structure::Framework#register
|
80
|
+
#
|
81
|
+
|
82
|
+
def scoped_base_path
|
83
|
+
if defined?(@isolated_from_parent_scoped_base_path)
|
84
|
+
nil
|
85
|
+
elsif defined?(@scoped_base_path)
|
86
|
+
@scoped_base_path
|
72
87
|
elsif parent
|
73
|
-
|
88
|
+
parent.scoped_base_path
|
74
89
|
else
|
75
|
-
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def has_scoped_base_path?
|
95
|
+
return false if defined? @isolated_from_parent_scoped_base_path
|
96
|
+
return true if defined? @scoped_base_path
|
97
|
+
return true if (parent and parent.has_scoped_base_path?)
|
98
|
+
return false
|
99
|
+
end
|
100
|
+
|
101
|
+
def set_scoped_base_path path
|
102
|
+
@scoped_base_path = path
|
103
|
+
end
|
104
|
+
|
105
|
+
def isolate_subgraph_from_scoped_base_path!
|
106
|
+
@isolated_from_parent_scoped_base_path = true
|
107
|
+
end
|
108
|
+
|
109
|
+
def forget_scoped_base_path!
|
110
|
+
remove_instance_variable :@scoped_base_path if defined? @scoped_base_path
|
111
|
+
remove_instance_variable :@isolated_from_parent_scoped_base_path if defined? @isolated_from_parent_scoped_base_path
|
112
|
+
parent.forget_scoped_base_path! if parent
|
113
|
+
end
|
114
|
+
|
115
|
+
def with_base_path base_path, &block
|
116
|
+
set_scoped_base_path base_path
|
117
|
+
klass = Class.new(::WebBlocks::Facade::Block)
|
118
|
+
klass.class_variable_set :@@default_base_path, base_path
|
119
|
+
klass.class_eval do
|
120
|
+
def handle *params, &block
|
121
|
+
subblock = super *params, &block
|
122
|
+
default_base_path = self.class.class_variable_get(:@@default_base_path).to_s
|
123
|
+
subblock.define_singleton_method(:default_base_path){ default_base_path }
|
124
|
+
subblock
|
125
|
+
end
|
126
|
+
end
|
127
|
+
register_facade :block, klass
|
128
|
+
instance_eval &block
|
129
|
+
register_facade :block, ::WebBlocks::Facade::Block
|
130
|
+
forget_scoped_base_path!
|
131
|
+
end
|
132
|
+
|
133
|
+
# Extending set_parent method from WebBlocks::Support::Attributes::Container, which is included by way of
|
134
|
+
# inheritance through self.class -> WebBlocks::Structure::Tree::Node -> WebBlocks::Structure::Tree::LeafNode.
|
135
|
+
# This is required for WebBlocks::Structure::Framework#register.
|
136
|
+
|
137
|
+
extend_method :set_parent do |parent|
|
138
|
+
parent_method parent
|
139
|
+
if has_scoped_base_path?
|
140
|
+
if has? :path
|
141
|
+
path = get(:path).to_s
|
142
|
+
set :path, "#{scoped_base_path}/#{path}" unless path[0,1] == '/'
|
143
|
+
isolate_subgraph_from_scoped_base_path!
|
144
|
+
end
|
76
145
|
end
|
77
146
|
end
|
78
147
|
|
148
|
+
##
|
149
|
+
# Methods available for interpreting and manipulating the block
|
150
|
+
#
|
151
|
+
|
152
|
+
def resolved_path
|
153
|
+
|
154
|
+
parents_except_root = parents
|
155
|
+
|
156
|
+
# we're not going to use the root's path for determining if there's an implicit path
|
157
|
+
root = parents_except_root.pop
|
158
|
+
|
159
|
+
# get the sub-paths
|
160
|
+
subpaths = []
|
161
|
+
parents_except_root.each do |p|
|
162
|
+
subpaths.unshift(p.get(:path)) if p.has?(:path)
|
163
|
+
end
|
164
|
+
|
165
|
+
if subpaths.length == 0
|
166
|
+
[self, parents_except_root].flatten.each do |p|
|
167
|
+
if p.respond_to? :default_base_path
|
168
|
+
subpaths.push(p.default_base_path)
|
169
|
+
break
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
subpaths.unshift(Pathname.new((root and root.has?(:path)) ? root.get(:path) : '.'))
|
175
|
+
|
176
|
+
subpaths << attributes[:path] if attributes.has_key?(:path)
|
177
|
+
|
178
|
+
begin
|
179
|
+
subpaths.reduce(:+).realpath
|
180
|
+
rescue => e
|
181
|
+
puts "Error resolving block #{self.route} to path #{subpaths.reduce(:+).to_json} from #{subpaths.to_json}"
|
182
|
+
raise e
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
79
187
|
def files
|
80
188
|
computed = []
|
81
189
|
children.each do |name,object|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'web_blocks/facade/external_component_block'
|
2
|
+
require 'web_blocks/facade/registration_scope'
|
2
3
|
require 'web_blocks/structure/block'
|
3
4
|
require 'web_blocks/structure/raw_file'
|
4
5
|
require 'web_blocks/support/tsort/hash'
|
@@ -7,22 +8,19 @@ module WebBlocks
|
|
7
8
|
module Structure
|
8
9
|
class Framework < Block
|
9
10
|
|
11
|
+
set :required, true
|
12
|
+
|
13
|
+
# FRAMEWORK DSL
|
14
|
+
|
10
15
|
register_facade :external_component_block, WebBlocks::Facade::ExternalComponentBlock
|
16
|
+
register_facade :registration_scope, WebBlocks::Facade::RegistrationScope
|
11
17
|
|
12
|
-
|
18
|
+
def after name, &block
|
19
|
+
for_notification "after_#{name}".to_sym, &block
|
20
|
+
end
|
13
21
|
|
14
|
-
def
|
15
|
-
name
|
16
|
-
path = hash[:path]
|
17
|
-
resolved_block_path = resolved_path + path
|
18
|
-
blockfile_path = resolved_block_path + "Blockfile.rb"
|
19
|
-
raise "Undefined blockfile for #{path}" unless File.exists?(blockfile_path)
|
20
|
-
isolated_facade_registration_scope do
|
21
|
-
block name do
|
22
|
-
set :base_path, resolved_block_path
|
23
|
-
end
|
24
|
-
instance_eval File.read(blockfile_path)
|
25
|
-
end
|
22
|
+
def before name, &block
|
23
|
+
for_notification "before_#{name}".to_sym, &block
|
26
24
|
end
|
27
25
|
|
28
26
|
def include *args
|
@@ -41,6 +39,43 @@ module WebBlocks
|
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
42
|
+
# FRAMEWORK METHODS
|
43
|
+
|
44
|
+
def register hash
|
45
|
+
name = hash[:name]
|
46
|
+
path = hash[:path]
|
47
|
+
resolved_block_path = resolved_path + path
|
48
|
+
blockfile_path = resolved_block_path + "Blockfile.rb"
|
49
|
+
raise "Undefined blockfile for #{path}" unless File.exists?(blockfile_path)
|
50
|
+
in_registration_scope resolved_block_path do
|
51
|
+
instance_eval File.read(blockfile_path)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def in_registration_scope resolved_block_path, &block
|
56
|
+
isolated_facade_registration_scope do
|
57
|
+
with_base_path(resolved_block_path) do
|
58
|
+
registration_scope :set, path: resolved_block_path
|
59
|
+
instance_eval &block
|
60
|
+
registration_scope :unset
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def for_notification name, &block
|
66
|
+
@notification = {} unless defined? @notification
|
67
|
+
@notification[name] = [] unless @notification.has_key?(name)
|
68
|
+
@notification[name].push block
|
69
|
+
end
|
70
|
+
|
71
|
+
def notify name, opts = {}
|
72
|
+
if defined?(@notification) and @notification.has_key?(name)
|
73
|
+
@notification[name].each do |proc|
|
74
|
+
instance_exec opts, &proc
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
44
79
|
def block_from_route route
|
45
80
|
block = self
|
46
81
|
route.each { |name| block = block.block(name) }
|
@@ -74,9 +109,7 @@ module WebBlocks
|
|
74
109
|
end
|
75
110
|
|
76
111
|
def get_file_load_order type = RawFile
|
77
|
-
|
78
112
|
::WebBlocks::Support::TSort::Hash.try_convert(adjacency_list).tsort.keep_if(){ |file| file.is_a? type }
|
79
|
-
|
80
113
|
end
|
81
114
|
|
82
115
|
end
|
@@ -27,6 +27,11 @@ module WebBlocks
|
|
27
27
|
:default => nil,
|
28
28
|
:desc => 'Path where WebBlocks should build products'
|
29
29
|
|
30
|
+
class_option :env,
|
31
|
+
:type => :string,
|
32
|
+
:default => nil,
|
33
|
+
:desc => 'Name of the environment'
|
34
|
+
|
30
35
|
no_commands do
|
31
36
|
|
32
37
|
def prepare_blocks!
|
@@ -62,10 +67,26 @@ module WebBlocks
|
|
62
67
|
include_routes_from_command_line! log if self.options.include
|
63
68
|
set_build_path_from_command_line!
|
64
69
|
|
70
|
+
framework.notify :after_prepare_blocks, runner: self, log: log
|
71
|
+
|
65
72
|
end
|
66
73
|
|
67
74
|
end
|
68
75
|
|
76
|
+
def reload_blocks! log
|
77
|
+
|
78
|
+
::WebBlocks::Framework.class_variable_set(:@@framework, ::WebBlocks::Structure::Framework.new('framework'))
|
79
|
+
|
80
|
+
initialize_root!
|
81
|
+
|
82
|
+
load_bower_registry! log
|
83
|
+
load_blockfile! log
|
84
|
+
include_own_routes! log
|
85
|
+
include_routes_from_command_line! log if self.options.include
|
86
|
+
set_build_path_from_command_line!
|
87
|
+
|
88
|
+
end
|
89
|
+
|
69
90
|
end
|
70
91
|
|
71
92
|
private
|
data/lib/web_blocks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.1.0.dev
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Bollens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -239,10 +239,12 @@ files:
|
|
239
239
|
- lib/web_blocks.rb
|
240
240
|
- lib/web_blocks/facade/base.rb
|
241
241
|
- lib/web_blocks/facade/block.rb
|
242
|
+
- lib/web_blocks/facade/directory_name_block.rb
|
242
243
|
- lib/web_blocks/facade/external_component_block.rb
|
243
244
|
- lib/web_blocks/facade/file_name_block.rb
|
244
245
|
- lib/web_blocks/facade/js_file.rb
|
245
246
|
- lib/web_blocks/facade/recursive_file_names_block.rb
|
247
|
+
- lib/web_blocks/facade/registration_scope.rb
|
246
248
|
- lib/web_blocks/facade/scss_file.rb
|
247
249
|
- lib/web_blocks/framework.rb
|
248
250
|
- lib/web_blocks/manager/bower.rb
|