Module: WhoNeedsWP

Defined in:
lib/who-needs-wp/css.rb,
lib/who-needs-wp/Content.rb,
lib/who-needs-wp/Sidebar.rb,
lib/who-needs-wp/sitemap.rb,
lib/who-needs-wp/keywords.rb,
lib/who-needs-wp/templates.rb,
lib/who-needs-wp/content/Page.rb,
lib/who-needs-wp/content/Post.rb,
lib/who-needs-wp/sidebar/twitter.rb,
lib/who-needs-wp/sidebar/latitude.rb,
lib/who-needs-wp/sidebar/delicious.rb,
lib/who-needs-wp/sidebar/pageindex.rb,
lib/who-needs-wp/sidebar/recentposts.rb

Defined Under Namespace

Classes: Content, Delicious, Latitude, Page, PageIndex, Post, RecentPosts, Sidebar, TwitterFeed, TwitterSearch, TwitterSidebar, YahooTermExtractor

Class Method Summary collapse

Class Method Details

.css(filename = "style.css") ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/who-needs-wp/css.rb', line 3

def self.css(filename="style.css")
  if @options[:stylesheet] == nil or @options[:stylesheet].empty?
  stylesheets_folder = File.expand_path(File.join(File.dirname(__FILE__), "stylesheets"))
  @logger.debug "Generating stylesheets from #{stylesheets_folder}"
  File.open(filename, "w") do |file|
    file.puts Sass::Engine.new(File.read("#{stylesheets_folder}/style.sass"), { :load_paths => [stylesheets_folder]}).to_css
  end
  end
end

.load_templatesObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/who-needs-wp/templates.rb', line 27

def self.load_templates
  template_folder = File.expand_path(File.join(File.dirname(__FILE__), "templates"))
  @template = Hash.new
  Dir.glob("#{template_folder}/*.haml").each do |template|
    # If a local template exists then over-write
    if File.exists? "templates/#{File.basename(template)}"
      template = "templates/#{File.basename(template)}"
    end
    @logger.debug "Loading template #{template}"
    @template[File.basename(template, '.haml')] = Haml::Engine.new(File.read(template))
  end
end

.render_html(filename, type, contents, title = "", tags = [], summary = "") ⇒ Object

Render the specified HTML contents within the layout template



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/who-needs-wp/templates.rb', line 9

def self.render_html(filename, type, contents, title = "", tags = [], summary = "")
  File.open(filename, "w") do |file|
    body = @template['body'].render(Object.new, {
      :content => contents,
      :options => @options,
      :sidebar => Sidebar.render_all,
      :layout_name => type
    })
    file.puts @template['layout'].render(Object.new, {
      :content => body,
      :options => @options,
      :title => title,
      :tags => tags,
      :summary => summary
    })
  end
end

.render_template(name, data) ⇒ Object

Render the specified template with the given options



3
4
5
6
# File 'lib/who-needs-wp/templates.rb', line 3

def self.render_template(name, data)
  data[:options] = @options
  @template[name].render(Object.new, data)
end

.sitemapObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/who-needs-wp/sitemap.rb', line 3

def self.sitemap
  document = REXML::Document.new
  urlset = document.add_element("urlset", { "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9"})
  Post.all.each do |post|
    url = REXML::Element.new("url")
    urlset.add(url)
    url.add_element("loc").text = post.url
    url.add_element("lastmod").text = post.created_at.strftime('%Y-%m-%d')
    url.add_element("priority").text = "0.5"
  end
  Page.all.each do |page|
    url = REXML::Element.new("url")
    urlset.add(url)
    url.add_element("loc").text = page.url
    url.add_element("priority").text = "0.8"
  end
  
  # Generate sitemap for index page
  url = REXML::Element.new("url")
  
  url.add_element("loc").text = WhoNeedsWP::options[:url] + "/index.html"
  if Post.all.length > 0 
    url.add_element("lastmod").text = Post.all[0].created_at.strftime('%Y-%m-%d')
  end
  url.add_element("priority").text = "1.0"
  urlset.add(url)

  # Write the XML document to a file
  File.open("sitemap.xml", "w") do |file|
    file.puts document
  end

  # Create a robots.txt which points to the sitemap.xml
  File.open("robots.txt", "w") do |file|
    file.puts "Sitemap: #{WhoNeedsWP::options[:url]}sitemap.xml"
  end
end