static 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +2 -0
- data/bin/cli.rbml +16 -2
- data/bin/static +3 -11
- data/lib/collection.rb +41 -6
- data/lib/extentions/string.rb +1 -1
- data/lib/page.rb +3 -0
- data/lib/site.rb +1 -0
- data/lib/static.rb +15 -2
- data/lib/xhtml.rb +16 -0
- data/templates/helpers/content.rb +393 -0
- data/templates/helpers/prototype.js +3277 -0
- metadata +4 -2
data/Manifest.txt
CHANGED
@@ -23,6 +23,8 @@ templates/disco/display
|
|
23
23
|
templates/disco/paginate
|
24
24
|
templates/disco/feed
|
25
25
|
templates/disco/link_list
|
26
|
+
templates/helpers/content.rb
|
27
|
+
templates/helpers/prototype.js
|
26
28
|
templates/layouts/default/contents.erbml
|
27
29
|
templates/layouts/default/main_navigation.erbml
|
28
30
|
templates/layouts/default/page_head.erbml
|
data/bin/cli.rbml
CHANGED
@@ -26,13 +26,14 @@ cli :name=>"static", :prompt=>"-> " do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
set :start do |args|
|
29
|
+
key(:editor){ @active = :editor }
|
29
30
|
key(:site){ @active = :site }
|
30
31
|
key(:collection){ @active = :collection }
|
31
32
|
key(:with)
|
32
33
|
flag(:help => 'h'){ puts "helpdocs for 'start' go here" }
|
33
34
|
|
34
35
|
process(args)
|
35
|
-
name = (remaining_argument == '' ? request_value('please enter a name: ') : remaining_argument)
|
36
|
+
name = (remaining_argument == '' ? request_value('please enter a name: ') : remaining_argument) unless @active == :editor
|
36
37
|
@active = ($active_site ? :collection : :site) unless @active
|
37
38
|
|
38
39
|
case @active
|
@@ -55,6 +56,18 @@ cli :name=>"static", :prompt=>"-> " do
|
|
55
56
|
else
|
56
57
|
puts 'gotta have a site to make a collection'
|
57
58
|
end
|
59
|
+
when :editor
|
60
|
+
$active_site.info['user_name'] ||= request_value 'username on your server: '
|
61
|
+
$active_site.info['server'] ||= {}
|
62
|
+
$active_site.info['local'] ||= {}
|
63
|
+
$active_site.info['server']['address'] ||= request_value 'server address (that you would use to ssh): '
|
64
|
+
$active_site.info['server']['directory'] ||= request_value 'directory on server (e.g. ~/www): '
|
65
|
+
$active_site.info['server']['link'] ||= request_value('web address of site home (e.g. somesite.com): ' ).as_http
|
66
|
+
$active_site.info['local']['link'] ||= request_value('local address of site home (e.g. localhost/~username/): ' ).as_http+"static/#{$active_site.info['working_name']}"
|
67
|
+
|
68
|
+
$active_site.info['server']['link'] = $active_site.info['server']['link'].as_http
|
69
|
+
$active_site.save_info 'site.info'
|
70
|
+
system "camping #{$active_site.home}helpers/content.rb"
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
@@ -236,7 +249,7 @@ cli :name=>"static", :prompt=>"-> " do
|
|
236
249
|
end
|
237
250
|
|
238
251
|
set :add do |args|
|
239
|
-
edit $active_collection.add_entry
|
252
|
+
edit $active_collection.add_entry[:file]
|
240
253
|
$active_collection.sanitize_listing
|
241
254
|
$active_collection.save_listing
|
242
255
|
end
|
@@ -298,6 +311,7 @@ cli :name=>"static", :prompt=>"-> " do
|
|
298
311
|
publish_feeds @blank
|
299
312
|
end
|
300
313
|
|
314
|
+
|
301
315
|
set :quit do
|
302
316
|
exit
|
303
317
|
end
|
data/bin/static
CHANGED
@@ -3,16 +3,8 @@
|
|
3
3
|
require File.dirname(__FILE__)+'/../lib/static'
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
$ENV['REPO_HOME'] = $ENV['STATIC_HOME']+'/repos/'
|
9
|
-
$ENV['SITE_BANK'] = $ENV['STATIC_HOME']+'projects/'
|
10
|
-
$ENV['TEMPLATE_HOME'] = $ENV['STATIC_HOME']+'.templates/'
|
11
|
-
$ENV['LAYOUT_HOME'] = $ENV['STATIC_HOME']+'layouts/'
|
12
|
-
$ENV['SCRIPT_HOME'] = $ENV['STATIC_HOME']+'lib/'
|
13
|
-
$ENV['TEMPLATE_BANK'] = File.dirname(__FILE__)+'/../templates'
|
14
|
-
|
15
|
-
|
6
|
+
include Static
|
7
|
+
Static::setup_home
|
16
8
|
include FileBase
|
17
9
|
|
18
10
|
#destroy $ENV['STATIC_HOME']
|
@@ -22,6 +14,7 @@ mkdir $ENV['STATIC_HOME'] unless exists? :folder, $ENV['STATIC_HOME']
|
|
22
14
|
mkdir $ENV['SITE_BANK'] unless exists? :folder, $ENV['SITE_BANK']
|
23
15
|
|
24
16
|
copy File.dirname(__FILE__)+'/../templates', $ENV['TEMPLATE_HOME'] unless exists? :folder, $ENV['TEMPLATE_HOME']
|
17
|
+
copy File.dirname(__FILE__)+'/../templates/helpers', $ENV['TEMPLATE_HOME']+'helpers' unless exists? :folder, $ENV['TEMPLATE_HOME']+'helpers'
|
25
18
|
move $ENV['TEMPLATE_HOME']+'layouts', $ENV['LAYOUT_HOME'] unless exists? :folder, $ENV['LAYOUT_HOME']
|
26
19
|
puts "home: #{$ENV['STATIC_HOME']}"
|
27
20
|
|
@@ -45,7 +38,6 @@ module Rbml
|
|
45
38
|
end
|
46
39
|
end
|
47
40
|
|
48
|
-
include Static
|
49
41
|
::Rbml::Processor.run(File.dirname(__FILE__)+'/cli.rbml')
|
50
42
|
|
51
43
|
__END__
|
data/lib/collection.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Collection
|
2
|
-
attr_accessor :name, :attrs, :base, :listing, :entries, :contents
|
2
|
+
attr_accessor :name, :attrs, :base, :listing, :entries, :contents, :unpublished
|
3
3
|
include FileBase
|
4
4
|
def initialize base, where, name
|
5
5
|
set_home where
|
@@ -8,6 +8,7 @@ class Collection
|
|
8
8
|
@attrs = []
|
9
9
|
@listing = []
|
10
10
|
@entries = []
|
11
|
+
@unpublished = []
|
11
12
|
setup_location 'collections'
|
12
13
|
set_home path+name
|
13
14
|
end
|
@@ -64,7 +65,8 @@ class Collection
|
|
64
65
|
add = true if value and not attrs[key]
|
65
66
|
end
|
66
67
|
}
|
67
|
-
|
68
|
+
item[:publish] = false unless add or item[:publish]
|
69
|
+
tmp << item
|
68
70
|
}
|
69
71
|
@listing = tmp
|
70
72
|
save_listing
|
@@ -93,10 +95,31 @@ class Collection
|
|
93
95
|
@listing ||= []
|
94
96
|
@listing = @listing.sort{|x, y| x[:id] <=> y[:id]}.reverse
|
95
97
|
end
|
98
|
+
def save_entry(id)
|
99
|
+
File.open( home+'entries/'+id, 'w' ) {|yf|
|
100
|
+
tmp={}
|
101
|
+
tmp[name] = find_entry id
|
102
|
+
tmp[name] = tmp[name].reject{|key, value| key.kind_of? Symbol }
|
103
|
+
YAML::dump( tmp, yf)
|
104
|
+
}
|
105
|
+
find_entry id
|
106
|
+
end
|
96
107
|
def load_entries
|
97
|
-
|
108
|
+
@entries = []
|
109
|
+
@unpublished = []
|
110
|
+
listing.each {|entry|
|
111
|
+
if entry[:publish]
|
112
|
+
@entries << load_entry(entry)
|
113
|
+
else
|
114
|
+
@unpublished << load_entry(entry)
|
115
|
+
end
|
116
|
+
}
|
98
117
|
entries
|
99
118
|
end
|
119
|
+
def delete entry
|
120
|
+
listing.delete_if{|e| e[:id] == entry }
|
121
|
+
save_listing
|
122
|
+
end
|
100
123
|
def load_entry(file)
|
101
124
|
tmp = nil
|
102
125
|
File.open( home+'entries/'+file[:id].to_s ) {|yf| tmp = YAML::load( yf )[name].merge(file)} rescue puts "loading entry -- #{$!}"
|
@@ -105,10 +128,11 @@ class Collection
|
|
105
128
|
def add_entry title=nil
|
106
129
|
timestamp = Time.now.to_i.to_s
|
107
130
|
title ||= timestamp
|
108
|
-
|
109
|
-
|
131
|
+
listing.unshift({:id => timestamp})
|
132
|
+
save_listing
|
110
133
|
write_template home+'attributes', home+'entries/'+timestamp
|
111
|
-
|
134
|
+
load_entries
|
135
|
+
return {:id => timestamp, :file => home+'entries/'+timestamp}
|
112
136
|
end
|
113
137
|
def publish
|
114
138
|
tmp = {}
|
@@ -120,6 +144,17 @@ class Collection
|
|
120
144
|
save_listing
|
121
145
|
end
|
122
146
|
|
147
|
+
def set_to_publish entry
|
148
|
+
listing.find{|e| e[:id] == entry}[:publish] = true
|
149
|
+
save_listing
|
150
|
+
end
|
151
|
+
|
152
|
+
def find_entry entry
|
153
|
+
tmp = entries.find{|e| e[:id] == entry}
|
154
|
+
tmp ||= unpublished.find{|e| e[:id] == entry}
|
155
|
+
tmp
|
156
|
+
end
|
157
|
+
|
123
158
|
|
124
159
|
end
|
125
160
|
|
data/lib/extentions/string.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
class String
|
4
|
-
def as_file; self.gsub(/([!?,]|[^a-zA-Z0-9\.]$)/, '').gsub(/[^a-zA-Z0-9
|
4
|
+
def as_file; self.gsub(/([!?,]|[^a-zA-Z0-9\.]$)/, '').gsub(/[^a-zA-Z0-9\.\/~]/, '_').downcase end
|
5
5
|
def as_folder; self.as_file+((self.as_file=~/\/$/||self=='') ? '' : '/') end
|
6
6
|
def as_ext; self[0,0]='.' unless self[0,1]=='.'|| self==''; self end
|
7
7
|
def as_file_title; self.as_file.gsub /_/, ' ' end
|
data/lib/page.rb
CHANGED
@@ -89,6 +89,9 @@
|
|
89
89
|
def load_contents
|
90
90
|
File.open(home+ 'contents/'+page_location+name.as_file+'.copy') { |yf| @contents = YAML::load( yf ) } rescue puts $!
|
91
91
|
end
|
92
|
+
def save_contents
|
93
|
+
File.open(home+ 'contents/'+page_location+name.as_file+'.copy', 'w') { |yf| YAML.dump(@contents, yf) }
|
94
|
+
end
|
92
95
|
|
93
96
|
def extentions
|
94
97
|
{
|
data/lib/site.rb
CHANGED
@@ -27,6 +27,7 @@ class Site
|
|
27
27
|
return nil if self.site_exists?(where, name)
|
28
28
|
site = Site.new(where, name, generate_to, templates)
|
29
29
|
site.mkdir(site.home+'project_info')
|
30
|
+
site.copy(templates+'helpers', site.home) rescue puts $!
|
30
31
|
site.setup_location 'project_info'
|
31
32
|
site.write_template templates+'site.map', site.path+'site.map'
|
32
33
|
site.write_template templates+'site.info', site.path+'site.info'
|
data/lib/static.rb
CHANGED
@@ -24,12 +24,23 @@ require 'rbml'
|
|
24
24
|
require 'xhtml'
|
25
25
|
|
26
26
|
$ENV = {}
|
27
|
-
$ENV['EDITOR'] = 'vi'
|
28
27
|
|
29
28
|
module Static
|
30
|
-
VERSION = '0.1.
|
29
|
+
VERSION = '0.1.3'
|
31
30
|
include FileBase
|
32
31
|
|
32
|
+
def setup_home
|
33
|
+
$ENV['EDITOR'] = 'vi'
|
34
|
+
$ENV['STATIC_HOME'] = "#{ENV['HOME']}/static/"
|
35
|
+
$ENV['STATIC_VIEWING'] = "#{ENV['HOME']}/Sites/static/"
|
36
|
+
$ENV['REPO_HOME'] = $ENV['STATIC_HOME']+'/repos/'
|
37
|
+
$ENV['SITE_BANK'] = $ENV['STATIC_HOME']+'projects/'
|
38
|
+
$ENV['TEMPLATE_HOME'] = $ENV['STATIC_HOME']+'.templates/'
|
39
|
+
$ENV['LAYOUT_HOME'] = $ENV['STATIC_HOME']+'layouts/'
|
40
|
+
$ENV['SCRIPT_HOME'] = $ENV['STATIC_HOME']+'lib/'
|
41
|
+
$ENV['TEMPLATE_BANK'] = File.dirname(__FILE__)+'/../templates'
|
42
|
+
end
|
43
|
+
|
33
44
|
def start_site name
|
34
45
|
site = Site.start($ENV['SITE_BANK'], name, $ENV['STATIC_VIEWING'], $ENV['TEMPLATE_HOME'])
|
35
46
|
site
|
@@ -109,6 +120,7 @@ module Static
|
|
109
120
|
def publish_feeds blank = nil
|
110
121
|
$active_site.info['feeds'].each do |name|
|
111
122
|
col = load_collection(name) #Generator.load(name).inspect
|
123
|
+
col.load_entries
|
112
124
|
col.publish
|
113
125
|
Generator.load col
|
114
126
|
Generator.act_on.instance_eval {
|
@@ -124,6 +136,7 @@ module Static
|
|
124
136
|
Generator.act_on.instance_eval { @level = nil; undef :level; undef :level=}
|
125
137
|
Generator.unload
|
126
138
|
end if $active_site.info['feeds']
|
139
|
+
|
127
140
|
unless blank
|
128
141
|
puts "rsync -avz #{$active_site.site_loc}/* #{$active_site.info['user_name']}@#{$active_site.info['server']['address']}:#{$active_site.info['server']['directory']}"
|
129
142
|
system "rsync -avz #{$active_site.site_loc}/* #{$active_site.info['user_name']}@#{$active_site.info['server']['address']}:#{$active_site.info['server']['directory']}"
|
data/lib/xhtml.rb
CHANGED
@@ -176,6 +176,22 @@ module Rbml
|
|
176
176
|
what
|
177
177
|
end
|
178
178
|
|
179
|
+
def site_map(options={}, item=nil, first_time=true)
|
180
|
+
pages = first_time ? "<ul>" : ''
|
181
|
+
item ||= $active_site.map['site_map']
|
182
|
+
case item
|
183
|
+
when String
|
184
|
+
pages << "<li>#{link_to(item.as_file)}</li>"
|
185
|
+
when Array : item.each {|i| pages << site_map(options, i, false)}
|
186
|
+
when Hash
|
187
|
+
item.each do |key, value|
|
188
|
+
pages << site_map(options, key, false)
|
189
|
+
pages << "<ul>#{site_map(options, value, false)}</ul>"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
pages << "</ul>" if first_time
|
193
|
+
pages
|
194
|
+
end
|
179
195
|
end
|
180
196
|
end
|
181
197
|
end
|
@@ -0,0 +1,393 @@
|
|
1
|
+
|
2
|
+
require 'camping'
|
3
|
+
require 'static'
|
4
|
+
|
5
|
+
include Static
|
6
|
+
Camping.goes :Content
|
7
|
+
|
8
|
+
@home = File.dirname(__FILE__)+'/..'
|
9
|
+
File.open("#{@home}/project_info/site.info") { |yf| $info = YAML::load( yf ) }
|
10
|
+
Static::setup_home
|
11
|
+
|
12
|
+
$active_site = load_site $info['working_name']
|
13
|
+
|
14
|
+
module Content::Controllers
|
15
|
+
class Static < R '/resource_bank/(.+)'
|
16
|
+
MIME_TYPES = {'.css' => 'text/css', '.js' => 'text/javascript', '.jpg' => 'image/jpeg'}
|
17
|
+
PATH = File.expand_path(File.dirname(__FILE__))
|
18
|
+
|
19
|
+
def get(path)
|
20
|
+
@headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || "text/plain"
|
21
|
+
unless path.include?("..")
|
22
|
+
@headers['X-Sendfile'] = "#{PATH}/#{path}"
|
23
|
+
else
|
24
|
+
@status = "403"
|
25
|
+
"403 - Invalid path"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class GenerateSite < R '/site/generate'
|
31
|
+
def get
|
32
|
+
$active_site.destroy $active_site.site_loc
|
33
|
+
$active_site.info['paginate'].each { |page, collection| paginate page } if $active_site.info['paginate']
|
34
|
+
$active_site.generate
|
35
|
+
publish_feeds :local
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class PublishSite < R '/site/publish'
|
40
|
+
def get
|
41
|
+
$active_site.destroy $active_site.site_loc
|
42
|
+
$active_site.info['paginate'].each { |page, collection| paginate page } if $active_site.info['paginate']
|
43
|
+
$active_site.generate
|
44
|
+
publish_feeds
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class HideCollection < R '/collection/hide/(.+)'
|
50
|
+
def get name
|
51
|
+
@headers['Content-Type'] = 'text/javascript'
|
52
|
+
@name = name
|
53
|
+
render :_hide_collection
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class ListCollection < R '/collection/list/(.+)'
|
58
|
+
def get name
|
59
|
+
@headers['Content-Type'] = 'text/javascript'
|
60
|
+
@name = name
|
61
|
+
@collection = load_collection name
|
62
|
+
render :_list_collection
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class ViewEntry < R '/collection/(.+)/entry/(.+)'
|
67
|
+
def get collection, entry
|
68
|
+
@headers['Content-Type'] = 'text/javascript'
|
69
|
+
@name = collection
|
70
|
+
@collection = load_collection collection
|
71
|
+
@collection.load_entries
|
72
|
+
@entry = @collection.find_entry entry
|
73
|
+
render :_view_entry
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class ReloadEntrySection < R '/reload/collection/(.+)/entry/(.+)/section/(.+)'
|
78
|
+
def get collection, entry, key
|
79
|
+
@headers['Content-Type'] = 'text/javascript'
|
80
|
+
@name = collection
|
81
|
+
@collection = load_collection collection
|
82
|
+
@collection.load_entries
|
83
|
+
@entry = @collection.find_entry entry
|
84
|
+
@section = key
|
85
|
+
render :_reload_entry_section
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class PublishEntry < R '/publish/collection/(\w+)/entry/(\w+)'
|
90
|
+
def get collection, entry
|
91
|
+
@headers['Content-Type'] = 'text/javascript'
|
92
|
+
@name = collection
|
93
|
+
@collection = load_collection collection
|
94
|
+
@collection.set_to_publish entry
|
95
|
+
@collection.load_entries
|
96
|
+
render :_list_collection
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class DeleteEntry < R '/delete/collection/(.+)/entry/(.+)'
|
101
|
+
def get collection, entry
|
102
|
+
@headers['Content-Type'] = 'text/javascript'
|
103
|
+
@name = collection
|
104
|
+
@collection = load_collection collection
|
105
|
+
@collection.delete entry
|
106
|
+
@collection.load_entries
|
107
|
+
render :_list_collection
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class EditEntry < R '/edit/collection/(.+)/entry/(.+)/section/(.+)'
|
112
|
+
def get collection, entry, key
|
113
|
+
@headers['Content-Type'] = 'text/javascript'
|
114
|
+
@name = collection
|
115
|
+
@collection = load_collection collection
|
116
|
+
@collection.load_entries
|
117
|
+
@entry = @collection.find_entry entry
|
118
|
+
@section = key
|
119
|
+
render :_edit_entry_section
|
120
|
+
end
|
121
|
+
|
122
|
+
def post collection, entry, key
|
123
|
+
@headers['Content-Type'] = 'text/javascript'
|
124
|
+
|
125
|
+
@name = collection
|
126
|
+
@collection = load_collection collection
|
127
|
+
@collection.load_entries
|
128
|
+
@collection.find_entry(entry)[key] = input["#{key}_value"]
|
129
|
+
@entry = @collection.save_entry entry
|
130
|
+
@section = key
|
131
|
+
render :_reload_entry_section
|
132
|
+
end
|
133
|
+
end
|
134
|
+
class Index < R '/'
|
135
|
+
def get
|
136
|
+
render :index
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class Content < R '/(\w+)'
|
141
|
+
def get page_name
|
142
|
+
@page = Page.find page_name.as_file
|
143
|
+
@page.load_contents
|
144
|
+
render :_content
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class Reload < R '/reload/(\w+)/(\w+)'
|
149
|
+
def get page_name, section
|
150
|
+
@page = Page.find page_name.as_file
|
151
|
+
@page.load_contents
|
152
|
+
@key = section
|
153
|
+
@value = @page.contents[section]
|
154
|
+
render :_section
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
class AddEntry < R '/add_entry/collection/(\w+)'
|
159
|
+
def get collection
|
160
|
+
@name = collection
|
161
|
+
@collection = load_collection collection
|
162
|
+
@collection.load_entries
|
163
|
+
@entry = @collection.add_entry
|
164
|
+
@entry = @collection.load_entry @entry
|
165
|
+
@collection.load_entries
|
166
|
+
render :_view_entry
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class Edit < R '/edit/(\w+)/(\w+)'
|
171
|
+
def get page_name, section
|
172
|
+
page = Page.find page_name.as_file
|
173
|
+
page.load_contents
|
174
|
+
@page_name = page_name.as_file
|
175
|
+
@text = page.contents[section]
|
176
|
+
@title = section
|
177
|
+
render :_edit_section
|
178
|
+
end
|
179
|
+
|
180
|
+
def post page_name, section
|
181
|
+
@headers['Content-Type'] = 'text/javascript'
|
182
|
+
@page = Page.find page_name.as_file
|
183
|
+
@page.load_contents
|
184
|
+
@old_key = section
|
185
|
+
@key = input["#{section}_key"]
|
186
|
+
@value = input["#{section}_value"]
|
187
|
+
if @key == section
|
188
|
+
@page.contents[section] = @value
|
189
|
+
else
|
190
|
+
@page.contents[section] = nil
|
191
|
+
@page.contents[@key] = @value
|
192
|
+
end
|
193
|
+
@page.save_contents
|
194
|
+
@page.load_contents
|
195
|
+
|
196
|
+
render :_reload_section
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
module Content::Views
|
202
|
+
def site_map(options={}, item=nil, first_time=true)
|
203
|
+
pages = first_time ? "<ul>" : ''
|
204
|
+
item ||= $active_site.map['site_map']
|
205
|
+
case item
|
206
|
+
when String
|
207
|
+
pages << "<li>#{link_to(item)}</li>"
|
208
|
+
when Array : item.each {|i| pages << site_map(options, i, false)}
|
209
|
+
when Hash
|
210
|
+
item.each do |key, value|
|
211
|
+
pages << site_map(options, key, false)
|
212
|
+
pages << "<ul>#{site_map(options, value, false)}</ul>"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
pages << "</ul>" if first_time
|
216
|
+
pages
|
217
|
+
end
|
218
|
+
|
219
|
+
def link_to page, name=nil; name||=page; a name, :href=>'#', :onclick => "new Ajax.Updater('main', '/#{page.as_file}',{asynchronous:true, evalScripts:true, method:'get'}); return false;" end
|
220
|
+
|
221
|
+
def layout
|
222
|
+
html do
|
223
|
+
head{
|
224
|
+
title { 'Content Editing For Static' }
|
225
|
+
script :src => "resource_bank/prototype.js", :type => "text/javascript"
|
226
|
+
}
|
227
|
+
body {
|
228
|
+
table {
|
229
|
+
ul{
|
230
|
+
li{
|
231
|
+
self << a('generate site locally', :href => '#', :onclick => "new Ajax.Request('site/generate', {asynchronous:true, evalScripts:true, method:'get'}); return false;")
|
232
|
+
}
|
233
|
+
li{
|
234
|
+
self << a('local preview', :href => $active_site.info['local']['link'], :target => 'blank')
|
235
|
+
} if $active_site.info['local'] and $active_site.info['local']['link']
|
236
|
+
li{
|
237
|
+
self << a('publish site', :href => '#', :onclick => "new Ajax.Request('site/publish', {asynchronous:true, evalScripts:true, method:'get'}); return false;")
|
238
|
+
} if $active_site.info['server'] and $active_site.info['server']['link'] and $active_site.info['server']['address'] and $active_site.info['server']['directory'] and $active_site.info['user_name']
|
239
|
+
li{
|
240
|
+
self << a('go to live site', :href => $active_site.info['server']['link'], :target => 'blank' )
|
241
|
+
} if $active_site.info['server'] and $active_site.info['server']['link']
|
242
|
+
}
|
243
|
+
tr{
|
244
|
+
td(:id => 'page_select', :valign=>'top', :width=> '250px'){
|
245
|
+
self<< site_map({}, $active_site.map['site_map'])
|
246
|
+
$active_site.info['feeds'].each do |f|
|
247
|
+
div(:id=>"#{f}_collection"){self << a(f, :href=>'#', :onclick => "new Ajax.Request('collection/list/#{f}', {asynchronous:true, evalScripts:true, method:'get'}); return false;")}
|
248
|
+
end if $active_site.info['feeds']
|
249
|
+
}
|
250
|
+
td(:id=>'main', :valign =>'top'){ self << yield }
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def index
|
258
|
+
p 'there are no instructions. do what feels right.'
|
259
|
+
end
|
260
|
+
|
261
|
+
def _content
|
262
|
+
h4 "copy for #{@page.name}"
|
263
|
+
if @page.contents['title']
|
264
|
+
span(:id => 'title'){
|
265
|
+
h4 {
|
266
|
+
self << a('title', :href=>"#", :onclick => "new Ajax.Updater('title', 'edit/#{@page.file_name}/title', { asynchronous:true, method:'get' });")
|
267
|
+
}
|
268
|
+
pre @page.contents['title']
|
269
|
+
}
|
270
|
+
end
|
271
|
+
@page.contents.each do |key, value|
|
272
|
+
unless key == 'title' or key == 'stylesheets'
|
273
|
+
span(:id => key){
|
274
|
+
h4 {
|
275
|
+
self << a(key, :href=>"#", :onclick => "new Ajax.Updater('#{key}', 'edit/#{@page.file_name}/#{key}', { asynchronous:true, method:'get' });")
|
276
|
+
}
|
277
|
+
pre value
|
278
|
+
}
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def _edit_section
|
284
|
+
form(:onsubmit => "new Ajax.Request('/edit/#{@page_name}/#{@title}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;"){
|
285
|
+
|
286
|
+
if @title == 'title'
|
287
|
+
h4 'title'
|
288
|
+
input :type => 'hidden', :value => @title, :name =>"#{@title}_key"
|
289
|
+
input :type => 'text', :name =>"#{@title}_value", :value => @text
|
290
|
+
else
|
291
|
+
input :type => 'text', :value => @title, :name =>"#{@title}_key"
|
292
|
+
textarea(:cols => '90', :rows => '30', :name => "#{@title}_value"){
|
293
|
+
self << @text
|
294
|
+
}
|
295
|
+
end
|
296
|
+
input :type => 'submit', :value => 'submit', :name => 'submit'
|
297
|
+
a 'cancel', :href=> "#", :onclick => "new Ajax.Updater('#{@title}', '/reload/#{@page_name}/#{@title}', {asynchronous:true, method:'get'}); return false;"
|
298
|
+
}
|
299
|
+
end
|
300
|
+
|
301
|
+
def _edit_entry_section
|
302
|
+
form(:onsubmit => "new Ajax.Request('/edit/collection/#{@name}/entry/#{@entry[:id]}/section/#{@section}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;"){
|
303
|
+
if @section == "title"
|
304
|
+
input :type => 'text', :name =>"title_value", :value => @entry[@section]
|
305
|
+
else
|
306
|
+
textarea(:cols => '90', :rows => '30', :name => "#{@section}_value"){
|
307
|
+
self << @entry[@section]
|
308
|
+
}
|
309
|
+
end
|
310
|
+
input :type => 'submit', :value => 'submit', :name => 'submit'
|
311
|
+
a 'cancel', :href=> "#", :onclick => "new Ajax.Updater('#{@section}_attribute', '/reload/collection/#{@name}/entry/#{@entry[:id]}/section/#{@section}', {asynchronous:true, method:'get'}); return false;"
|
312
|
+
}
|
313
|
+
end
|
314
|
+
|
315
|
+
def _reload_entry_section
|
316
|
+
self << _list_collection if @section == 'title'
|
317
|
+
self << "$('attribute_#{@section}').replace("
|
318
|
+
if @section =="title"
|
319
|
+
h4(:id => "attribute_title"){self<< a(@entry["title"]||@entry[:id], :href=>'#', :onclick => "new Ajax.Updater('attribute_title', 'edit/collection/#{@name}/entry/#{@entry[:id]}/section/title', { asynchronous:true, method:'get' });")}
|
320
|
+
else
|
321
|
+
span(:id => "attribute_#{@section}"){
|
322
|
+
self << a(@section, :href=>"#", :onclick => "new Ajax.Updater('attribute_#{@section}', 'edit/collection/#{@name}/entry/#{@entry[:id]}/section/#{@section}', { asynchronous:true, method:'get' });")
|
323
|
+
pre(@entry[@section])
|
324
|
+
}
|
325
|
+
end
|
326
|
+
self << ")"
|
327
|
+
end
|
328
|
+
|
329
|
+
def _section
|
330
|
+
span(:id => @key){
|
331
|
+
h4 {
|
332
|
+
self << a(@key, :href=>"#", :onclick => "new Ajax.Updater('#{@key}', 'edit/#{@page.file_name}/#{@key}', { asynchronous:true, method:'get' });")
|
333
|
+
}
|
334
|
+
pre @value
|
335
|
+
}
|
336
|
+
end
|
337
|
+
|
338
|
+
def _reload_section
|
339
|
+
self << "$('#{@old_key}').replace("
|
340
|
+
_section
|
341
|
+
self << ")"
|
342
|
+
end
|
343
|
+
|
344
|
+
def _hide_collection
|
345
|
+
self << "$('#{@name}_collection').replace("
|
346
|
+
div(:id=>"#{@name}_collection"){self << a(@name, :href=>'#', :onclick => "new Ajax.Request('collection/list/#{@name}', {asynchronous:true, evalScripts:true, method:'get'}); return false;")}
|
347
|
+
self << ")"
|
348
|
+
end
|
349
|
+
|
350
|
+
def _list_collection
|
351
|
+
self << "$('#{@name}_collection').replace("
|
352
|
+
div(:id => "#{@name}_collection"){
|
353
|
+
a(@name, :href=>'#', :onclick => "new Ajax.Request('collection/hide/#{@name}', {asynchronous:true, evalScripts:true, method:'get'}); return false;")
|
354
|
+
a("+add+", :href=>'#', :onclick => "new Ajax.Updater('main', 'add_entry/collection/#{@name}', {asynchronous:true, evalScripts:true, method:'get'}); return false;")
|
355
|
+
ul{
|
356
|
+
li "unpublished"
|
357
|
+
@collection.unpublished.each do |e|
|
358
|
+
li{
|
359
|
+
self << a(e['title']||e[:id], :href=>'#', :onclick=>"new Ajax.Updater('main', 'collection/#{@name}/entry/#{e[:id]}',{asynchronous:true, evalScripts:true, method:'get'}); return false; ")
|
360
|
+
self << a('publish', :href => '#', :onclick=>"new Ajax.Request('publish/collection/#{@name}/entry/#{e[:id]}',{asynchronous:true, evalScripts:true, method:'get'}); return false; ")
|
361
|
+
self << a('delete', :href => '#', :onclick=>"new Ajax.Request('delete/collection/#{@name}/entry/#{e[:id]}',{asynchronous:true, evalScripts:true, method:'get'}); return false; ")
|
362
|
+
}
|
363
|
+
end
|
364
|
+
}
|
365
|
+
ul{
|
366
|
+
li "published"
|
367
|
+
@collection.entries.each do |e|
|
368
|
+
li{
|
369
|
+
self << a(e['title']||e[:id], :href=>'#', :onclick=>"new Ajax.Updater('main', 'collection/#{@name}/entry/#{e[:id]}',{asynchronous:true, evalScripts:true, method:'get'}); return false; ")
|
370
|
+
unless e[:publish]
|
371
|
+
self << a('publish', :href => '#', :onclick=>"new Ajax.Request('publish/collection/#{@name}/entry/#{e[:id]}', {asynchronous:true, evalScripts:true, method:'get'}); return false; ")
|
372
|
+
self << a('delete', :href => '#', :onclick=>"new Ajax.Request('delete/collection/#{@name}/entry/#{e[:id]}',{asynchronous:true, evalScripts:true, method:'get'}); return false; ")
|
373
|
+
end
|
374
|
+
}
|
375
|
+
end
|
376
|
+
}
|
377
|
+
}
|
378
|
+
self << ");"
|
379
|
+
end
|
380
|
+
|
381
|
+
def _view_entry
|
382
|
+
h4(:id => "attribute_title"){self<< a(@entry["title"]||@entry[:id], :href=>'#', :onclick => "new Ajax.Updater('attribute_title', 'edit/collection/#{@name}/entry/#{@entry[:id]}/section/title', { asynchronous:true, method:'get' });")}
|
383
|
+
@entry.each {|key, value|
|
384
|
+
unless key=='title' or key.kind_of? Symbol
|
385
|
+
span(:id => "attribute_#{key}"){
|
386
|
+
self << a(key, :href=>"#", :onclick => "new Ajax.Updater('attribute_#{key}', 'edit/collection/#{@name}/entry/#{@entry[:id]}/section/#{key}', { asynchronous:true, method:'get' });")
|
387
|
+
pre(@entry[key])
|
388
|
+
}
|
389
|
+
end
|
390
|
+
}
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|