static 0.1.3 → 1.0.0

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.
@@ -1,43 +0,0 @@
1
-
2
- class Class # :nodoc:
3
- def cattr_reader(*syms)
4
- syms.flatten.each do |sym|
5
- class_eval(<<-EOS, __FILE__, __LINE__)
6
- unless defined? @@#{sym}
7
- @@#{sym} = nil
8
- end
9
-
10
- def self.#{sym}
11
- @@#{sym}
12
- end
13
-
14
- def #{sym}
15
- @@#{sym}
16
- end
17
- EOS
18
- end
19
- end
20
-
21
- def cattr_writer(*syms)
22
- syms.flatten.each do |sym|
23
- class_eval(<<-EOS, __FILE__, __LINE__)
24
- unless defined? @@#{sym}
25
- @@#{sym} = nil
26
- end
27
-
28
- def self.#{sym}=(obj)
29
- @@#{sym} = obj
30
- end
31
-
32
- def #{sym}=(obj)
33
- @@#{sym} = obj
34
- end
35
- EOS
36
- end
37
- end
38
-
39
- def cattr_accessor(*syms)
40
- cattr_reader(*syms)
41
- cattr_writer(*syms)
42
- end
43
- end
@@ -1,11 +0,0 @@
1
-
2
-
3
- class String
4
- def as_file; self.gsub(/([!?,]|[^a-zA-Z0-9\.]$)/, '').gsub(/[^a-zA-Z0-9\.\/~]/, '_').downcase end
5
- def as_folder; self.as_file+((self.as_file=~/\/$/||self=='') ? '' : '/') end
6
- def as_ext; self[0,0]='.' unless self[0,1]=='.'|| self==''; self end
7
- def as_file_title; self.as_file.gsub /_/, ' ' end
8
- def filename_as_symbol; self.as_file.to_sym end
9
- def as_http; self =~ /^http\:\/\// ? "http://#{self.gsub(/^http\:\/\//, '').as_folder}" : "http://#{self.as_folder}" end
10
- end
11
-
@@ -1,84 +0,0 @@
1
-
2
- require 'erb'
3
- require 'fileutils'
4
-
5
- module FileBase
6
- include FileUtils
7
-
8
- Home = ''
9
- def home; (@home||Home).as_folder end
10
- def set_home(here)
11
- mkdir here unless exists? :folder, here
12
- @home=here
13
- end
14
-
15
- def location; (@location||'').as_folder end
16
- def set_location where; @location=where end
17
- def setup_location where; @location=where; mkdir path unless exists? :folder, path end
18
- def reset_location; @location='' end
19
- def has_location?; location!='' end
20
-
21
- def path; home+location end
22
- def file_path; home+location+filename end
23
-
24
- def exists? type, item
25
- return false unless File.exist? item
26
- truth = case type
27
- when :folder
28
- return(File.directory?(item))
29
- when :file
30
- return(!File.directory?(item))
31
- else
32
- return(true)
33
- end
34
- end
35
-
36
- def items_under(pth, match=nil)
37
- match||=''
38
- folders = []
39
- files = []
40
- Dir.entries(pth).each { |item| (exists?(:folder, pth.as_folder+item) ? folders << item : files << item) unless item[0,1]=='.' or not item=~/#{match}/}
41
- {:folders => folders, :files => files}
42
- end
43
-
44
-
45
- def move(from, to=home)
46
- FileUtils.mv from, to
47
- end
48
-
49
- def copy(from, to=home)
50
- FileUtils.cp_r from, to
51
- end
52
-
53
- def mkdir where, force=false
54
- begin
55
- Dir.mkdir where
56
- rescue
57
- raise $! unless force
58
- destroy where
59
- mkdir where
60
- end
61
- where
62
- end
63
-
64
- def make_dir path, force=false
65
- mkdir path, force
66
- puts 'creating '+path
67
- end
68
-
69
- def destroy what
70
- FileUtils.rm_rf what
71
- puts 'destroying '+what
72
- end
73
-
74
- def write(contents, where)
75
- File.open(where, 'w'){ |f| f << contents }
76
- end
77
- def write_template what, where
78
- write ERB.new(File.read(what)).result(binding), where
79
- end
80
-
81
- alias loc location
82
- alias loc= set_location
83
- end
84
-
@@ -1,20 +0,0 @@
1
- class Generator
2
- include Singleton
3
- cattr_accessor :act_on, :actors
4
-
5
- def self.load(what)
6
- self.actors ||= []
7
- self.actors << self.act_on if self.act_on
8
- self.act_on = what
9
- end
10
-
11
- def self.unload
12
- self.act_on = self.actors.shift
13
- end
14
-
15
- def self.method_missing(sym, *args)
16
- act_on.send(sym, *args)
17
- end
18
- end
19
-
20
-
@@ -1,135 +0,0 @@
1
- class Page
2
- include FileBase
3
-
4
- cattr_accessor :pages
5
- @@pages=[]
6
- attr_accessor :name, :subs, :page_location, :contents, :stylesheets, :index, :site_location, :site_base, :breadcrumbs
7
- @@templates = {}
8
-
9
- def initialize(name, home, location, generate_to, subs=nil, index=nil)
10
- @home = home
11
- @page_location = location
12
- @name = name
13
- @subs = subs
14
- @site_base = generate_to.as_folder
15
- @index = index
16
- @breadcrumbs = []
17
- @stylesheets = []
18
- pages << self
19
- end
20
-
21
- def included_in? page_name, all_levels=false
22
- ans = (file_name == page_name.to_s or Page.find(page_name).subs.include? name)
23
- subs.each { |sub| ans = Page.find(sub.as_file).included_in?(page_name, all_levels) } if all_levels and !ans
24
- ans
25
- end
26
-
27
- def file_name
28
- name.as_file
29
- end
30
- def to_s
31
- name.downcase
32
- end
33
- def self.find(name)
34
- item = nil
35
- name = name.to_s
36
- self.pages.each{ |p| item = p if p.file_name==name.as_file}
37
- item
38
- end
39
-
40
- def index?; @index end
41
-
42
- def generate collection_name
43
- stylesheets << contents['stylesheets'] if contents['stylesheets']
44
- mkdir in_site_location unless exists?(:folder, in_site_location) or index?
45
- collection = load_collection(collection_name) if collection_name
46
- if collection
47
- Generator.class_eval { cattr_accessor :include_text }
48
- Generator.include_text = File.read home+"blueprint/#{page_location}_#{collection_name}_for_#{file_name}/#{collection.first}"
49
- write ::Rbml::Processor.new.instance_eval(File.read(home+'base/default.rbml')), in_site_location+'index.html'
50
- puts 'writing the index'
51
- collection.each { |col|
52
- Generator.include_text = File.read home+"blueprint/#{page_location}_#{collection_name}_for_#{file_name}/#{col}"
53
- write ::Rbml::Processor.new.instance_eval(File.read(home+'base/default.rbml')), in_site_location+col+'.html'
54
- puts "writing the entry for #{col}"
55
- }
56
- Generator.class_eval { @include_text = nil }
57
- else
58
- write ::Rbml::Processor.new.instance_eval(File.read(home+'base/default.rbml')), in_site_location+'index.html'
59
- end
60
- puts "writing #{in_site_location}index.html"
61
- end
62
-
63
- def load_collection name
64
- stuff = nil
65
- File.open(home+ 'blueprint/'+page_location+"_#{name}_for_#{file_name}/page.list") { |yf| stuff = YAML::load( yf ) }
66
- stuff
67
- end
68
-
69
- def in_site_location
70
- (index? ? site_base : ( has_subs? && subs.kind_of?(Array) ? site_base+page_location : site_base+page_location+name.as_file )).as_folder
71
- end
72
- def in_site_link
73
- in_site_location.sub(site_base, '')
74
- end
75
- def level
76
- tmp = (index? || has_subs? && subs.kind_of?(Array)) ? '' : '../'
77
- tmp+page_location.gsub(/\w+\//, '../')
78
- end
79
-
80
- def menu_title
81
- case subs
82
- when Array : name
83
- when String : subs
84
- else
85
- nil
86
- end
87
- end
88
-
89
- def load_contents
90
- File.open(home+ 'contents/'+page_location+name.as_file+'.copy') { |yf| @contents = YAML::load( yf ) } rescue puts $!
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
95
-
96
- def extentions
97
- {
98
- :contents => '.copy',
99
- :blueprint => '.rbml',
100
- :page => '.html'
101
- }
102
- end
103
-
104
- def make(type)
105
- page_path = home+type.to_s+'/'+page_location
106
- mkdir page_path unless exists? :folder, page_path
107
- template_file = case type
108
- when :contents : {:main => home+'layout/copy/page.copy', :sub => home+'layout/copy/submenu.copy'}
109
- when :blueprint : {:main => home+'layout/contents.erbml', :sub => home+'layout/submenu.erbml'}
110
- end
111
-
112
- if subs && subs.kind_of?(Array)
113
- unless exists?(:file, page_path+'submenu'+extentions[type])
114
- unless type == :contents
115
- write_template template_file[:sub], page_path+'_submenu'+extentions[type]
116
- puts "writing #{page_path}submenu#{extentions[type]}"
117
- end
118
- else
119
- puts "#{page_path}submenu#{extentions[type]} already exists"
120
- end
121
- end
122
- unless exists?(:file, page_path+name.as_file+extentions[type])
123
- write_template template_file[:main], page_path+name.as_file+extentions[type]
124
- puts "writing #{page_path}#{name.as_file}#{extentions[type]}"
125
- else
126
- puts "#{page_path}#{name.as_file}#{extentions[type]} already exists"
127
- end
128
- end
129
-
130
- def has_subs?
131
- subs && !subs.empty?
132
- end
133
- end
134
-
135
-
@@ -1,153 +0,0 @@
1
- class Site
2
- include FileBase
3
-
4
- attr_accessor :name, :map, :info, :pages, :main_links, :site_loc
5
-
6
- def initialize(where, name, generate_to, templates=nil)
7
- set_home where+name
8
- @name = name
9
- @pages = []
10
- @main_links = []
11
- mkdir generate_to unless exists? :folder, generate_to
12
- @site_loc = generate_to + name
13
- end
14
-
15
- def self.load(where, name, generate_to, templates)
16
- return nil unless self.site_exists?(where, name)
17
- s = self.new(where, name, generate_to, templates)
18
- s.load_info
19
- s.load_pages
20
- s
21
- end
22
-
23
- def self.site_exists?(where, name)
24
- (exists?(:folder, where+name) && exists?(:folder, where+name+'/project_info'))
25
- end
26
- def self.start where, name, generate_to, templates
27
- return nil if self.site_exists?(where, name)
28
- site = Site.new(where, name, generate_to, templates)
29
- site.mkdir(site.home+'project_info')
30
- site.copy(templates+'helpers', site.home) rescue puts $!
31
- site.setup_location 'project_info'
32
- site.write_template templates+'site.map', site.path+'site.map'
33
- site.write_template templates+'site.info', site.path+'site.info'
34
- site.load_info
35
- site
36
- end
37
-
38
- def load_info(file=nil)
39
- File.open(home+ 'project_info/site.map') { |yf| @map = YAML::load( yf ) } unless file=='site.info'
40
- File.open(home+'project_info/site.info') { |yf| @info = YAML::load( yf ) } unless file=='site.map'
41
- end
42
-
43
- def save_info(file=nil)
44
- File.open(home+'project_info/site.map', 'w') { |yf| YAML.dump(@map, yf) } unless file=='site.info'
45
- File.open(home+'project_info/site.info', 'w') { |yf| YAML.dump(@info, yf) } unless file=='site.map'
46
- end
47
-
48
- def set_layout(name, address)
49
- copy address+name, home+'layout/' unless exists? :folder, home+'layout' rescue puts $!
50
- info['layout'] = {'name' => name, 'address' => address}
51
- end
52
-
53
- def load_pages
54
- gather_pages
55
- make_breadcrumbs
56
- end
57
- def gather_pages(page=nil, first_time=true, parent=nil)
58
- index = nil
59
- if first_time
60
- reset_location
61
- @pages = []
62
- page ||= map
63
- else
64
- index = true if @pages.empty?
65
- end
66
- case page
67
- when String : pages << Page.new(page, home, location, site_loc, parent, index)
68
- when Array then
69
- tmp = page.dup
70
- gather_pages(tmp.shift, false, parent) while(tmp.size > 0)
71
- when Hash then
72
- page.each { |page_name, sub_pages|
73
- unless first_time
74
- set_location(pages.empty? ? location : location+page_name )
75
- pages << Page.new(page_name, home, location, site_loc, sub_pages, index)
76
- else
77
- page_name = nil
78
- end
79
- gather_pages(sub_pages, false, page_name)
80
- set_location location.sub(page_name.as_file+'/', '') if page_name
81
- }
82
- else
83
- return nil
84
- end
85
- end
86
-
87
- def make_breadcrumbs
88
- pages.each do |page|
89
- page.breadcrumbs << page.name.as_file
90
- page.subs.each { |p|
91
- if p.kind_of?(Hash)
92
- p.each{ |k, v|
93
- tmp = Page.find(k)
94
- tmp.breadcrumbs << page.breadcrumbs }
95
- else
96
- tmp = Page.find(p).breadcrumbs << page.breadcrumbs
97
- end
98
- } if page.has_subs? && page.subs.kind_of?(Array)
99
- page.breadcrumbs.flatten!
100
- end
101
- end
102
-
103
- def load_main_links
104
- map['site_map'].each { |page|
105
- case page
106
- when String
107
- main_links << page
108
- when Hash
109
- page.each { |name, subs| main_links << name }
110
- end
111
- }
112
- end
113
-
114
- def build_header
115
- write_template home+"layout/page_head.erbml", home+'base/page_head.rbml'
116
- write_template home+"layout/main_navigation.erbml", home+'base/main_navigation.rbml'
117
- end
118
-
119
- def build(type)
120
- setup_location(type.to_s)
121
- if type == :blueprint
122
- @main_links = []
123
- copy home+'layout/structure', home+'base'
124
- begin
125
- copy home+'layout/stylesheets', home+'base/stylesheets'
126
- puts 'copied stylesheets'
127
- rescue
128
- puts "There are no stylesheets associated with this layout"
129
- end
130
- copy home+'layout/resources', home+'base/resources' rescue puts "There are no resources associated with this layout"
131
- copy home+'layout/scripts', home+'base/scripts' rescue puts "There are no scripts associated with this layout"
132
- load_main_links
133
- build_header
134
- end
135
- pages.each{|page| page.make(type)}
136
- end
137
-
138
- def generate
139
- mkdir site_loc unless exists? :folder, site_loc
140
- copy home+'base/stylesheets', site_loc rescue puts $!
141
- copy home+'base/resources', site_loc rescue puts $!
142
- copy home+'base/scripts', site_loc rescue puts $!
143
- pages.each do |page|
144
- page.stylesheets = []
145
- Generator.load(page)
146
- page.load_contents
147
- page.stylesheets << info['stylesheets'] if info['stylesheets']
148
- page.generate info['paginate'] ? info['paginate'][page.file_name] : nil rescue puts "site generator -- #{$!}"
149
- Generator.unload
150
- end
151
- end
152
- end
153
-