Class: YurtCMS
- Inherits:
-
Object
- Object
- YurtCMS
- Defined in:
- lib/yurtcms.rb
Instance Attribute Summary collapse
-
#data_store ⇒ Object
readonly
Returns the value of attribute data_store.
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#metatags ⇒ Object
readonly
Returns the value of attribute metatags.
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#web_root ⇒ Object
readonly
Returns the value of attribute web_root.
-
#yurt_root ⇒ Object
readonly
Returns the value of attribute yurt_root.
Instance Method Summary collapse
- #delete(obj) ⇒ Object
- #get_dir_listing(path) ⇒ Object
- #get_file_metadata(path) ⇒ Object
-
#initialize(yurt_root) ⇒ YurtCMS
constructor
A new instance of YurtCMS.
- #make_content_as_yaml(input) ⇒ Object
- #make_metatags(input) ⇒ Object
- #make_new_dir(path, name) ⇒ Object
- #make_placeholder(path, template) ⇒ Object
- #merge(path, file) ⇒ Object
- #parse_content(c) ⇒ Object
- #path_to_content(path) ⇒ Object
- #path_to_metatags(path) ⇒ Object
- #path_to_orig_content(path) ⇒ Object
- #path_to_placeholder(path) ⇒ Object
- #sanitize_filename(f) ⇒ Object
- #sanitize_path(path) ⇒ Object
- #write_all_files(input) ⇒ Object
- #write_file(path, contents) ⇒ Object
Constructor Details
#initialize(yurt_root) ⇒ YurtCMS
Returns a new instance of YurtCMS.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/yurtcms.rb', line 5 def initialize yurt_root require 'rubygems' require 'bluecloth' # i used to have require_gem, but i don't think it's needed require 'rubypants' require 'parse_ssi' @yurt_root = sanitize_path( yurt_root ) @data_store = [ @yurt_root, "content/" ].join @web_root = [ @yurt_root, "htdocs/" ].join @includes = [ @web_root, "includes/content/" ].join @metatags = ".metatags" @partial = ".partial" @ext = ".html" @ssi = ParseSSI.new(@web_root) end |
Instance Attribute Details
#data_store ⇒ Object (readonly)
Returns the value of attribute data_store.
4 5 6 |
# File 'lib/yurtcms.rb', line 4 def data_store @data_store end |
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
4 5 6 |
# File 'lib/yurtcms.rb', line 4 def ext @ext end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
4 5 6 |
# File 'lib/yurtcms.rb', line 4 def includes @includes end |
#metatags ⇒ Object (readonly)
Returns the value of attribute metatags.
4 5 6 |
# File 'lib/yurtcms.rb', line 4 def @metatags end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
4 5 6 |
# File 'lib/yurtcms.rb', line 4 def partial @partial end |
#web_root ⇒ Object (readonly)
Returns the value of attribute web_root.
4 5 6 |
# File 'lib/yurtcms.rb', line 4 def web_root @web_root end |
#yurt_root ⇒ Object (readonly)
Returns the value of attribute yurt_root.
4 5 6 |
# File 'lib/yurtcms.rb', line 4 def yurt_root @yurt_root end |
Instance Method Details
#delete(obj) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/yurtcms.rb', line 120 def delete obj f = path_to_orig_content( obj ) if File.exists?( f ) if File.ftype( f ) == "directory" Dir.delete( f ) [ :path_to_content, :path_to_placeholder ].each do |p| f = send( p, obj ).gsub(/\.html/, '') Dir.delete( f ) end else = YAML.load( File.open( f ) ) File.delete( f ) if ['partial'] == 'y' File.delete( path_to_content( obj ) ) else [ :path_to_metatags, :path_to_content, :path_to_placeholder ].each do |p| f = send( p, obj ) File.delete( f ) end end end end end |
#get_dir_listing(path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/yurtcms.rb', line 41 def get_dir_listing path @contents = Hash.new Dir.chdir( path_to_orig_content( path ) ) do Dir.foreach(".") do |entry| @contents[entry] = [ File.ftype(entry) ] unless ( entry =~ /^\./ or entry =~ /~$/ ) end end @contents end |
#get_file_metadata(path) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/yurtcms.rb', line 150 def path = YAML.load( File.open( path_to_orig_content( path ) ) ) [ "filename" ] = File.basename( path_to_orig_content( path ) ) [ "path" ] = File.dirname( path ) end |
#make_content_as_yaml(input) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/yurtcms.rb', line 81 def make_content_as_yaml input content = Hash.new if input.partial == "y" content[ "partial" ] = input.partial else content[ "title" ] = input.title content[ "description" ] = input.description content[ "keywords" ] = input.keywords content[ "template" ] = input.template end content[ "content" ] = input.content content.to_yaml end |
#make_metatags(input) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/yurtcms.rb', line 96 def input t = @ssi.set_tag('TITLE', input.title) if input.title =~ /\w/ d = @ssi.set_tag('DESCRIPTION', input.description) if input.description =~ /\w/ k = @ssi.set_tag('KEYWORDS', input.keywords) if input.keywords =~ /\w/ [ t, d, k ].join end |
#make_new_dir(path, name) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/yurtcms.rb', line 69 def make_new_dir path, name p = merge( path, sanitize_filename( name ) ) Dir.mkdir( [ @data_store, p ].join ) Dir.mkdir( [ @includes, p ].join ) Dir.mkdir( [ @web_root, p ].join ) File.chmod( 0777, [ @data_store, p ].join ) File.chmod( 0777, [ @includes, p ].join ) File.chmod( 0777, [ @web_root, p ].join ) end |
#make_placeholder(path, template) ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/yurtcms.rb', line 109 def make_placeholder path, template if template == nil or template == "" template = "template.html" end [ @ssi.set_tag('PAGE', path), @ssi.virtual_include_tag('/includes/' + template), ].join end |
#merge(path, file) ⇒ Object
21 22 23 |
# File 'lib/yurtcms.rb', line 21 def merge path, file [ path, '/', file ].join.gsub( /\/\/*/, "/" ) end |
#parse_content(c) ⇒ Object
104 105 106 107 |
# File 'lib/yurtcms.rb', line 104 def parse_content c #RubyPants.new(BlueCloth.new(c).to_html,1).to_html BlueCloth.new(c).to_html end |
#path_to_content(path) ⇒ Object
33 34 35 |
# File 'lib/yurtcms.rb', line 33 def path_to_content path [ @includes, path, @ext ].join end |
#path_to_metatags(path) ⇒ Object
29 30 31 |
# File 'lib/yurtcms.rb', line 29 def path [ @includes, path, @metatags, @ext ].join end |
#path_to_orig_content(path) ⇒ Object
25 26 27 |
# File 'lib/yurtcms.rb', line 25 def path_to_orig_content path [ @data_store, path ].join end |
#path_to_placeholder(path) ⇒ Object
37 38 39 |
# File 'lib/yurtcms.rb', line 37 def path_to_placeholder path [ @web_root, path, @ext].join end |
#sanitize_filename(f) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/yurtcms.rb', line 62 def sanitize_filename f f.gsub!(/^\//, "") f.gsub!(/[^\w\.\-]/, "_") f end |
#sanitize_path(path) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/yurtcms.rb', line 52 def sanitize_path path if path == "" "/" else path.gsub!( /^\//, '' ) path.gsub!( /\/$/, '' ) [ '/', path, '/' ].join.gsub( /\/\/*/,"/" ) end end |
#write_all_files(input) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/yurtcms.rb', line 168 def write_all_files input path = merge( input.path, sanitize_filename( input.filename ) ) write_file( path_to_orig_content( path ), make_content_as_yaml( input ) ) write_file( path_to_content( path ), parse_content( input.content ) ) if input.partial != "y" write_file( ( path ), ( input ) ) write_file( path_to_placeholder( path ), make_placeholder( path, input.template ) ) end end |
#write_file(path, contents) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/yurtcms.rb', line 158 def write_file path, contents f = File.new( path, "w" ) f.puts contents f.close begin File.chmod(0776,path) rescue end end |