Class: Marsdawn::Site::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/marsdawn/site/page.rb

Direct Known Subclasses

SearchPage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc_info, page, site) ⇒ Page

Returns a new instance of Page.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/marsdawn/site/page.rb', line 11

def initialize doc_info, page, site
  @doc_info = doc_info
  @site = site
  front_matter = page[:front_matter]
  @sysinfo = page[:sysinfo]
  @uri = @sysinfo[:uri]
  @title = front_matter[:title]
  @content = page[:content]
  @type = @sysinfo[:type]
  @level = @sysinfo[:level]
  @search_word = ''
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/marsdawn/site/page.rb', line 9

def content
  @content
end

#levelObject (readonly)

Returns the value of attribute level.



9
10
11
# File 'lib/marsdawn/site/page.rb', line 9

def level
  @level
end

#siteObject (readonly)

Returns the value of attribute site.



9
10
11
# File 'lib/marsdawn/site/page.rb', line 9

def site
  @site
end

#sysinfoObject (readonly)

Returns the value of attribute sysinfo.



9
10
11
# File 'lib/marsdawn/site/page.rb', line 9

def sysinfo
  @sysinfo
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/marsdawn/site/page.rb', line 9

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/marsdawn/site/page.rb', line 9

def type
  @type
end

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/marsdawn/site/page.rb', line 9

def uri
  @uri
end

Instance Method Details



24
25
26
# File 'lib/marsdawn/site/page.rb', line 24

def breadcrumb
  @breadcrumb ||= Marsdawn::Site::Breadcrumb.new(@site, @sysinfo[:breadcrumb])
end


48
49
50
# File 'lib/marsdawn/site/page.rb', line 48

def link
  @link ||= Marsdawn::Site::Link.new(@site, @uri, @title)
end

#neighborObject



28
29
30
# File 'lib/marsdawn/site/page.rb', line 28

def neighbor
  @neighbor ||= @site.index.neighbor(@uri)
end


44
45
46
# File 'lib/marsdawn/site/page.rb', line 44

def page_nav
  @page_nav ||= Marsdawn::Site::PageNav.new(@site, @sysinfo[:prev_page], @sysinfo[:next_page])
end

#parentObject



36
37
38
# File 'lib/marsdawn/site/page.rb', line 36

def parent
  @parent ||= Marsdawn::Site::Link.new(@site, @sysinfo[:parent]) unless @sysinfo[:parent].nil?
end

#search_boxObject



52
53
54
# File 'lib/marsdawn/site/page.rb', line 52

def search_box
  @search_box ||= Marsdawn::Site::SearchBox.new(@site, @search_word)
end

#to_html(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/marsdawn/site/page.rb', line 60

def to_html options={}
  <<-"EOS"
  <div class="main-container">
  <div class="container">
    <div class="row">
      <div class="col-lg-3 sidebar">
        <nav>#{neighbor}</nav>
      </div>
      <div class="col-lg-9 content">
        <p>contents</p>
      </div>
    </div>
  </div>
  </div>
  EOS
end

#to_page_html(options = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/marsdawn/site/page.rb', line 77

def to_page_html options={}
  opts = {
    css: ['http://dev.screw-axis.com/marsdawn/style.css'],
    js: [],
    title: CGI.escapeHTML(@title),
    title_suffix: " | #{CGI.escapeHTML(@site.title)}",
    lang: @doc_info[:lang],
    charset: @doc_info[:encoding]
  }.merge(options)
  css_html = opts[:css].map{|file| %!<link rel="stylesheet" href="#{file}" type="text/css" />!}.join("\n")
  js_html = opts[:js].map{|file| %!<script src="#{file}"></script>!}.join("\n")
  %|<!DOCTYPE html>
  <html lang="#{opts[:lang]}">
  <head>
    <meta charset="#{opts[:encoding]}" />
    <title>#{opts[:title]}#{opts[:title_suffix]}</title>
    #{css_html}
    #{js_html}
  </head>
  <body>
    <div id="container">
      <div id="site-header"><h1 id="site-title">#{@site.title_link}</h1></div>
      <div id="side-menu">
        #{search_box}
        <nav>#{neighbor}</nav>
      </div>
      <div id="site-body">
        <div id="main-content">
          <div id="breadcrumb"><nav>#{breadcrumb}</nav></div>
          <div id="page-content">#{@content}</div>
          <div id="under-index">#{under}</div>
          <div id="page-nav">#{page_nav}</div>
        </div>
        <div class="clear"></div>
      </div>
    </div>
  </body>
  </html>|
end

#to_sObject



56
57
58
# File 'lib/marsdawn/site/page.rb', line 56

def to_s
  to_html
end

#topObject



32
33
34
# File 'lib/marsdawn/site/page.rb', line 32

def top
  @site.top
end

#underObject



40
41
42
# File 'lib/marsdawn/site/page.rb', line 40

def under
  @under ||= @site.index.under(@uri)
end