stasis 0.1.19 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stasis.rb +20 -9
- data/lib/stasis/dev_mode.rb +7 -3
- data/lib/stasis/plugin.rb +2 -1
- data/lib/stasis/plugins/before.rb +8 -2
- data/lib/stasis/plugins/helpers.rb +7 -1
- data/lib/stasis/plugins/ignore.rb +7 -1
- data/lib/stasis/plugins/layout.rb +7 -1
- data/lib/stasis/plugins/priority.rb +7 -1
- data/stasis.gemspec +1 -1
- metadata +3 -3
data/lib/stasis.rb
CHANGED
@@ -79,25 +79,26 @@ class Stasis
|
|
79
79
|
@destination = args[0] || @root + '/public'
|
80
80
|
@destination = File.expand_path(@destination, @root)
|
81
81
|
|
82
|
+
load_paths unless options[:development]
|
83
|
+
|
84
|
+
# Create plugin instances.
|
85
|
+
@plugins = find_plugins.collect { |klass| klass.new(self) }
|
86
|
+
|
87
|
+
load_controllers
|
88
|
+
end
|
89
|
+
|
90
|
+
def load_paths
|
82
91
|
# Create an `Array` of paths that Stasis will act upon.
|
83
92
|
@paths = Dir.glob("#{@root}/**/*", File::FNM_DOTMATCH)
|
84
|
-
|
93
|
+
|
85
94
|
# Reject paths that are directories or within the destination directory.
|
86
95
|
@paths.reject! do |path|
|
87
96
|
!File.file?(path) || path[0..@destination.length-1] == @destination
|
88
97
|
end
|
89
98
|
|
90
|
-
# Create plugin instances.
|
91
|
-
@plugins = find_plugins.collect { |klass| klass.new(self) }
|
92
|
-
|
93
|
-
# Create a controller instance.
|
94
|
-
@controller = Controller.new(self)
|
95
|
-
|
96
99
|
# Reject paths that are controllers.
|
97
100
|
@paths.reject! do |path|
|
98
101
|
if File.basename(path) == 'controller.rb'
|
99
|
-
# Add controller to `Controller` instance.
|
100
|
-
@controller._add(path)
|
101
102
|
true
|
102
103
|
else
|
103
104
|
false
|
@@ -105,6 +106,16 @@ class Stasis
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
109
|
+
def load_controllers
|
110
|
+
# Create a controller instance.
|
111
|
+
@controller = Controller.new(self)
|
112
|
+
|
113
|
+
# Reload controllers
|
114
|
+
Dir["#{@root}/**/controller.rb"].each do |path|
|
115
|
+
@controller._add(path) unless path[0..@destination.length-1] == @destination
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
108
119
|
def render(*only)
|
109
120
|
collect = {}
|
110
121
|
render_options = {}
|
data/lib/stasis/dev_mode.rb
CHANGED
@@ -14,6 +14,7 @@ class Stasis
|
|
14
14
|
|
15
15
|
@dir = dir
|
16
16
|
@options = options
|
17
|
+
@options[:development] ||= true
|
17
18
|
|
18
19
|
@stasis = Stasis.new(*[ @dir, @options[:public], @options ].compact)
|
19
20
|
|
@@ -34,7 +35,7 @@ class Stasis
|
|
34
35
|
dw.add_observer { render }
|
35
36
|
dw.start
|
36
37
|
|
37
|
-
if options[:development]
|
38
|
+
if options[:development].is_a?(::Integer)
|
38
39
|
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes
|
39
40
|
mime_types.store 'js', 'application/javascript'
|
40
41
|
|
@@ -43,7 +44,7 @@ class Stasis
|
|
43
44
|
:DocumentRoot => @stasis.destination,
|
44
45
|
:Logger => WEBrick::Log.new("/dev/null"),
|
45
46
|
:MimeTypes => mime_types,
|
46
|
-
:Port => options[:development]
|
47
|
+
:Port => options[:development]
|
47
48
|
)
|
48
49
|
|
49
50
|
['INT', 'TERM'].each do |signal|
|
@@ -61,6 +62,9 @@ class Stasis
|
|
61
62
|
def render
|
62
63
|
puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Regenerating #{@options[:only] ? @options[:only].join(', ') : 'project'}..."
|
63
64
|
begin
|
65
|
+
@stasis.load_paths
|
66
|
+
@stasis.trigger(:reset)
|
67
|
+
@stasis.load_controllers
|
64
68
|
@stasis.render(*[ @options[:only] ].flatten.compact)
|
65
69
|
rescue Exception => e
|
66
70
|
puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Error: #{e.message}`"
|
@@ -70,4 +74,4 @@ class Stasis
|
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
73
|
-
end
|
77
|
+
end
|
data/lib/stasis/plugin.rb
CHANGED
@@ -5,10 +5,11 @@ class Stasis
|
|
5
5
|
before_render :before_render
|
6
6
|
controller_method :before
|
7
7
|
priority 1
|
8
|
+
reset :reset
|
8
9
|
|
9
10
|
def initialize(stasis)
|
10
11
|
@stasis = stasis
|
11
|
-
|
12
|
+
reset
|
12
13
|
end
|
13
14
|
|
14
15
|
# This method is bound to all controllers. Stores a block in the `@blocks` `Hash`,
|
@@ -46,5 +47,10 @@ class Stasis
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
50
|
+
|
51
|
+
# This event resets all instance variables.
|
52
|
+
def reset
|
53
|
+
@blocks = {}
|
54
|
+
end
|
49
55
|
end
|
50
|
-
end
|
56
|
+
end
|
@@ -3,10 +3,11 @@ class Stasis
|
|
3
3
|
|
4
4
|
controller_method :helpers
|
5
5
|
before_render :before_render
|
6
|
+
reset :reset
|
6
7
|
|
7
8
|
def initialize(stasis)
|
8
9
|
@stasis = stasis
|
9
|
-
|
10
|
+
reset
|
10
11
|
end
|
11
12
|
|
12
13
|
# This event triggers before each file renders through Stasis. For each helper
|
@@ -25,5 +26,10 @@ class Stasis
|
|
25
26
|
@blocks << [ @stasis.path, block ]
|
26
27
|
end
|
27
28
|
end
|
29
|
+
|
30
|
+
# This event resets all instance variables.
|
31
|
+
def reset
|
32
|
+
@blocks = []
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
@@ -3,10 +3,11 @@ class Stasis
|
|
3
3
|
|
4
4
|
before_render :before_render
|
5
5
|
controller_method :ignore
|
6
|
+
reset :reset
|
6
7
|
|
7
8
|
def initialize(stasis)
|
8
9
|
@stasis = stasis
|
9
|
-
|
10
|
+
reset
|
10
11
|
end
|
11
12
|
|
12
13
|
# This event triggers before each file renders. Rejects any `paths` that are included
|
@@ -31,5 +32,10 @@ class Stasis
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
35
|
+
|
36
|
+
# This event resets all instance variables.
|
37
|
+
def reset
|
38
|
+
@ignore = {}
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
@@ -4,10 +4,11 @@ class Stasis
|
|
4
4
|
action_method :layout => :layout_action
|
5
5
|
before_render :before_render
|
6
6
|
controller_method :layout => :layout_controller
|
7
|
+
reset :reset
|
7
8
|
|
8
9
|
def initialize(stasis)
|
9
10
|
@stasis = stasis
|
10
|
-
|
11
|
+
reset
|
11
12
|
end
|
12
13
|
|
13
14
|
# This event triggers before each file renders through Stasis. It sets the `action`
|
@@ -79,5 +80,10 @@ class Stasis
|
|
79
80
|
hash
|
80
81
|
}
|
81
82
|
end
|
83
|
+
|
84
|
+
# This event resets all instance variables.
|
85
|
+
def reset
|
86
|
+
@layouts = {}
|
87
|
+
end
|
82
88
|
end
|
83
89
|
end
|
@@ -5,10 +5,11 @@ class Stasis
|
|
5
5
|
before_all :before_all
|
6
6
|
controller_method :priority
|
7
7
|
priority 2
|
8
|
+
reset :reset
|
8
9
|
|
9
10
|
def initialize(stasis)
|
10
11
|
@stasis = stasis
|
11
|
-
|
12
|
+
reset
|
12
13
|
end
|
13
14
|
|
14
15
|
# This event triggers before all files render through Stasis. Collect matching
|
@@ -37,5 +38,10 @@ class Stasis
|
|
37
38
|
end
|
38
39
|
@priorities.merge!(hash)
|
39
40
|
end
|
41
|
+
|
42
|
+
# This event resets all instance variables.
|
43
|
+
def reset
|
44
|
+
@priorities = {}
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
data/stasis.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stasis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 20
|
10
|
+
version: 0.1.20
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Winton Welsh
|