Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit b6f900a

Browse files
committed
big update / search engine works
1 parent 6ec8111 commit b6f900a

32 files changed

+139423
-601
lines changed

app/app.js.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
require_tree './components'
22
require_tree './stores'
3+
require_tree './operations'
4+
5+
36

47
# following only required for development (find a way to build without for production)
58
require 'opal_hot_reloader'

app/components/docs/docs_page.rb

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
class DocsPage < Hyperloop::Router::Component
22

3-
3+
44
before_mount do
55
SidebarStore.hide
66
end
77

88
render(DIV) do
9-
puts match.url
9+
#puts match.url
1010

11-
section_name = "docs"
11+
section = "docs"
1212
displaytitle = "Hyperloop Documentation"
1313

14-
sidebar = PageToc(history: params.history, location: params.location, section: section_name).as_node
15-
body = PageBody(section: section_name).as_node
14+
sidebar = PageToc(history: history, location: location, section: section).as_node
15+
body = PageBody(section: section).as_node
1616

1717

18-
Route('/docs/:repo', exact: true) do
19-
puts "we have a repo"
20-
end
21-
22-
Route('/docs/:repo/:file', exact: true) do
23-
puts "we have a repo and file"
24-
end
25-
26-
Route('/docs/:repo/:file/:slug', exact: true) do
27-
puts "we have a repo and file and slug"
28-
end
29-
30-
PageLayout(sidebar_component: sidebar, body_component: body, page_title: displaytitle, section: section_name, loaded: SiteStore.sections[section_name].loaded?)
18+
# Route('/docs/:repo', exact: true) do
19+
# puts "we have a repo"
20+
# end
21+
22+
# Route('/docs/:repo/:file', exact: true) do
23+
# puts "we have a repo and file"
24+
# end
25+
26+
# Route("#{match.url}", exact: false) do |m, l, h|
27+
# puts "we have only a section name #{match.url}"
28+
# PageLayout(section: match.url, match: m, location: l, history: h)
29+
# end
30+
31+
# Route("#{match.url}/:page_name", exact: false) do |m, l, h|
32+
# puts "we have a section name #{match.url} and a page name"
33+
# PageLayout(section: match.url, match: m, location: l, history: h)
34+
# end
35+
36+
PageLayout(sidebar_component: sidebar,
37+
body_component: body,
38+
page_title: displaytitle,
39+
section: section,
40+
loaded: SiteStore.sections[section].loaded?,
41+
history: history,
42+
location: location)
3143

3244
end
3345

app/components/router/app_router.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ class AppRouter < Hyperloop::Router
1616
DIV {
1717
Switch do
1818
Route('/', exact: true, mounts: HomePage)
19-
Route('/start', exact: false, mounts: StartPage)
19+
Route('/start', exact: false) { |m, l, h| StartPage(match: m, location: l, history: h) }
2020
Route('/installation', exact: true, mounts: InstallationPage)
2121
Route('/tutorials', exact: true, mounts: TutorialsPage)
2222
Route('/gems', exact: true, mounts: GemsPage)
2323
Route('/tools', exact: true, mounts: ToolsPage)
2424
Route('/docs', exact: false) { |m, l, h| DocsPage(match: m, location: l, history: h) }
25-
25+
Route('/searchresult', exact: false) { |m, l, h| SearchResultPage(match: m, location: l, history: h) }
2626
end
2727
}
2828
end
29+
30+
2931
end
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
class SearchResultBody < Hyperloop::Router::Component
3+
4+
param :history
5+
param :location
6+
param :section
7+
8+
9+
def gotoslug slug, sectionname, pageid
10+
11+
NavigationStore.mutate.slug ""
12+
pagetogo = SiteStore.sections[sectionname].pages[pageid]
13+
SiteStore.sections[sectionname].set_current_page pagetogo
14+
15+
NavigationStore.mutate.accordionindex pageid
16+
NavigationStore.mutate.slug slug
17+
18+
history.push "/#{sectionname}/#{pagetogo[:name]}/#{slug}"
19+
20+
end
21+
22+
def highlight(text, search_string)
23+
keywords = search_string.strip.split(" ").compact.uniq
24+
matcher = Regexp.new( '(' + keywords.join("|") + ')' )
25+
highlighted = text.gsub(matcher) { |match| "<a class='ui teal label'>#{match}</a>" }
26+
return highlighted
27+
end
28+
29+
30+
31+
render do
32+
33+
DIV(class: 'searchresultcontent') do
34+
35+
36+
37+
SearchEngineStore.allresults.each_with_index do |result, index|
38+
39+
resulthtmlparagraph = ""
40+
resultpagename = ""
41+
resultheadingname = ""
42+
resultheadingslug = ""
43+
resultsectionname = ""
44+
resultpageid = ""
45+
46+
SiteStore.sections[SearchEngineStore.previoussectionquery].pages.each_with_index do |page, index|
47+
48+
page[:headings].each do |heading|
49+
if (heading[:id] == result[:ref])
50+
resultsectionname = heading[:sectionname]
51+
resultpageid = heading[:pageid]
52+
resultpagename = heading[:pagename]
53+
resultheadingname = heading[:text]
54+
resultheadingslug = heading[:slug]
55+
resulthtmlparagraph = heading[:paragraphs].join(' ')
56+
end
57+
end
58+
59+
end
60+
61+
62+
H2(class: 'ui header') do
63+
IMG(src: 'dist/images/icons/gear.png')
64+
DIV(class: 'content') do
65+
66+
A() do
67+
DIV(dangerously_set_inner_HTML:
68+
{ __html:
69+
"#{index+1}. In #{resultpagename}: #{highlight(resultheadingname, result[:matchingwords]) } <a class='ui black label'>#{result[:nbresults]} results</a>"
70+
})
71+
72+
end.on(:click) { gotoslug(resultheadingslug, resultsectionname, resultpageid) }
73+
74+
# A(class:'ui black label') {"#{result[:nbresults]} results" }
75+
76+
DIV(class: 'sub header') do
77+
"_______________"
78+
end
79+
80+
end
81+
82+
end
83+
84+
DIV(dangerously_set_inner_HTML: { __html: highlight(resulthtmlparagraph, result[:matchingwords]) })
85+
86+
BR()
87+
end
88+
89+
end
90+
91+
92+
end
93+
94+
95+
96+
97+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
class SearchResultPage < Hyperloop::Router::Component
3+
4+
after_mount do
5+
Element['html, body'].animate({
6+
scrollTop: 0
7+
}, :slow)
8+
end
9+
10+
render do
11+
12+
section = "docs"
13+
displaytitle = "Search results for { #{SearchEngineStore.querystring} }"
14+
15+
sidebar = SearchResultSidebar(history: history, location: location, section: section).as_node
16+
body = SearchResultBody(history: history, location: location, section: section).as_node
17+
18+
PageLayout(sidebar_component: sidebar,
19+
body_component: body,
20+
page_title: displaytitle,
21+
section: section,
22+
loaded: true,
23+
history: history,
24+
location: location)
25+
26+
end
27+
28+
29+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
class ReactYahooSticky < Hyperloop::Component
3+
imports 'YahooSticky'
4+
end
5+
6+
class SearchResultSidebar < Hyperloop::Component
7+
8+
param :history
9+
param :location
10+
param :section
11+
12+
render do
13+
Sem.Rail(close: true, dividing: false, position: 'left') do
14+
ReactYahooSticky(enable: true, top: 50) do
15+
DIV(class: 'ui sticky visible transition') do
16+
H1(){"#{SearchEngineStore.nbresults} results found."}
17+
H2(){"in #{SearchEngineStore.allresults.length} chapters"}
18+
end
19+
end
20+
end
21+
end
22+
23+
end

app/components/shared/app_menu.rb

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
class AppMenu < Hyperloop::Router::Component
22

33
param :section
4-
4+
55
render do
66

77
DIV(class: 'following bar fixed') do
88
DIV(class: 'ui page grid') do
99
DIV(class: 'column') do
10+
1011
DIV(class: 'ui logo shape') do
1112
DIV(class: 'sides') do
1213
DIV(class: 'active learn side') do
@@ -17,16 +18,18 @@ class AppMenu < Hyperloop::Router::Component
1718

1819
end
1920
end
21+
2022
DIV(class: 'ui inverted right floated secondary menu') do
21-
DIV(class: 'item') do
22-
IFRAME(class: 'github', src: 'http://ghbtns.com/github-btn.html?user=ruby-hyperloop&repo=hyperloop&type=watch&count=true', allowTransparency: 'true', frameBorder: '0', scrolling: '0', width: '100', height: '20')
23-
end
23+
# DIV(class: 'item') do
24+
# IFRAME(class: 'github', src: 'http://ghbtns.com/github-btn.html?user=ruby-hyperloop&repo=hyperloop&type=watch&count=true', allowTransparency: 'true', frameBorder: '0', scrolling: '0', width: '100', height: '20')
25+
# end
2426
DIV(class: 'ui language floating dropdown link item', id: 'languages') do
2527
I(class: 'world icon')
2628
DIV(class: 'text') { 'English' }
2729
DIV(class: 'menu')
2830
end
2931
end
32+
3033
DIV(class: 'ui large secondary network menu') do
3134
A(class: 'view-ui item') do
3235
I(class: 'sidebar icon')
@@ -39,11 +42,26 @@ class AppMenu < Hyperloop::Router::Component
3942

4043
if (params.section != 'home')
4144
Sem.MenuItem {
42-
SiteSearch(section: params.section)
45+
SiteSearch(section: params.section, history: history, location: location)
46+
}
47+
48+
Sem.MenuItem {
49+
#puts "MATCH #{location.pathname == "/searchresult"}"
50+
if (!(SearchEngineStore.querystring.empty?) && !(location.pathname == "/searchresult"))
51+
Sem.Button(color: 'pink') {"See results for: { #{SearchEngineStore.querystring} }"}.on(:click) do
52+
params.history.push "/searchresult"
53+
end
54+
end
4355
}
56+
4457
end
4558

59+
Sem.MenuItem {
60+
IFRAME(class: 'github', src: 'http://ghbtns.com/github-btn.html?user=ruby-hyperloop&repo=hyperloop&type=watch&count=true', allowTransparency: 'true', frameBorder: '0', scrolling: '0', width: '100', height: '20')
61+
}
62+
4663
end
64+
4765
end
4866
end
4967
end

app/components/shared/md_converter.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# https://www.npmjs.com/package/marked#block-level-renderer-methods
22

33
class MdConverter
4-
def initialize md
4+
def initialize md, sectionname, sectionid, pageid, pagename
55
@md = md.gsub 'ruby runable', 'ruby-runable' #the space messes up the parsing
6+
@sectionname = sectionname
7+
@sectionid = sectionid
8+
@pageid = pageid
9+
@pagename = pagename
610
@headings = []
11+
@paragraphs = []
712
@code_blocks = []
13+
14+
@headings_index = 0
15+
816
process
917
end
1018

@@ -20,9 +28,12 @@ def headings
2028
@headings
2129
end
2230

31+
32+
2333
def process
2434
`var renderer = new Marked.Renderer()`
2535
`renderer.heading = #{lambda {|text, level| on_heading(text, level)} }`
36+
`renderer.paragraph = #{lambda {|text| on_paragraph(text)} }`
2637
`renderer.code = #{lambda {|code, lang| on_code(code, lang)} }`
2738
`renderer.codespan = #{lambda {|code| on_codespan(code)} }`
2839
`renderer.blockquote = #{lambda {|quote| on_blockquote(quote)} }`
@@ -59,11 +70,23 @@ def on_blockquote quote
5970

6071
def on_heading text, level
6172
heading = {}
73+
heading[:id] = "#{@sectionid}-#{@pageid}-#{@headings_index}"
74+
heading[:sectionname] = @sectionname
75+
heading[:pageid] = @pageid
76+
heading[:pagename] = @pagename
6277
heading[:text] = text
6378
heading[:level] = level
6479
heading[:slug] = text.downcase.gsub(/[^\w]+/g, '-')
80+
heading[:paragraphs] = []
81+
@headings_index += 1
82+
6583
@headings << heading
6684
"<h#{level} class='doc_h#{level} chapteranchor' id='#{heading[:slug]}'>#{text}</h#{level}>"
6785
end
6886

87+
def on_paragraph text
88+
@headings[@headings_index-1][:paragraphs] << "<p>#{text}</p>"
89+
"<p>#{text}</p>"
90+
end
91+
6992
end

app/components/shared/modal_dialog.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class ModalDialog < Hyperloop::Component
22

33
render do
44

5-
Sem.Modal(size: :large, open: (SearchResultModalStore.visible ? true : false)) do
5+
Sem.Modal(size: :large,open: (SearchResultModalStore.visible ? true : false)) do
66
Sem.ModalHeader {"Search Results: "}
77
Sem.ModalContent(image: true, scrolling: true) do
88
Sem.Image(size: 'massive', src: 'dist/images/hyperloop-logo-title.png', wrapped: true) {}
@@ -18,6 +18,8 @@ class ModalDialog < Hyperloop::Component
1818
end
1919
end
2020

21+
22+
2123
end
2224

2325
end

0 commit comments

Comments
 (0)