Skip to content

Add local docs #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gulpfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ rt = require 'react-templates'
map = require 'map-stream'
path = require 'path'
del = require 'del'
gutil = require 'gulp-util'
which = require('npm-which') __dirname

$ =
root: './src/root/*'
coffee: ['./src/coffee/popup.coffee', './src/coffee/background.coffee']
coffee: ['./src/coffee/popup.coffee', './src/coffee/addlocal.coffee', './src/coffee/background.coffee']
rt: './src/components/'
rtopt: modules: 'commonjs'
font: './node_modules/font-awesome/fonts/*.woff2'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"scripts": {
"start": "gulp watch",
"gulp": "gulp",
"test": "jest"
},
"jest": {
Expand Down
43 changes: 43 additions & 0 deletions src/coffee/addlocal.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
_ = require 'lodash'
domready = require 'domready'
React = require 'react/addons'
Addlocal = require '../components/addlocal/'
datastore = require './lib/datastore'
convert = require './lib/convert'

CONT_URL = 'https://github.com/TechDocs/TechDocs'

addPath = (sitefiles, current, path) ->
curSf = _.find sitefiles, (obj) -> obj.id == current
# calculate original path
path = if curSf.origin? then convert.reverse path, curSf.rules else path
# calculate translated path for each
sitefiles.map (sf) ->
sf.path = if sf.origin? then convert path, sf.rules else path
sf

domready ->
chrome.tabs.getSelected window.id, (tab) ->
if curSf = datastore.getOneMatchPrefix tab.url, ['url']
curPath = tab.url.replace curSf.url, ''
orgId = if curSf.origin then curSf.origin else curSf.id

# At first, get data in local
translations = datastore.getListEq orgId, ['origin', 'id'], (results) ->
# If there're no cache, get data from remote
add_to_local.setProps translations: addPath results, curSf.id, curPath
# Calculate Paths
translations = addPath translations, curSf.id, curPath

props =
title: orgId || 'search'
url: tab.url
tabId: tab.id
contributingUrl: CONT_URL
current: curSf?.id || ''
translations: translations || []
index: datastore.getIndex()
reload: datastore.reload

addlocal = React.render Addlocal(props), document.body

12 changes: 12 additions & 0 deletions src/components/addlocal/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
React = require 'react/addons'
template = require './template.rt.js'

module.exports = React.createFactory React.createClass

getInitialState: ->
title: ''
baseUrl: ''
matchPattern: ''

render: template

38 changes: 38 additions & 0 deletions src/components/addlocal/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.popup > p {
margin: 0;
padding: 1em;
}
.popup > ul {
margin: 0;
padding: .5em 0;
list-style: none;
}
.popup > header {
border-bottom: 1px dotted #ddd;
padding: .9em 1em .9em;
color: #ccc;
text-align: center;
}
.popup > footer {
border-top: 1px dotted #ddd;
padding: .5em 1em .7em;
color: #ccc;
text-align: center;
}
.popup-reload {
position: absolute;
left: 1em;
color: #999;
}
.popup-reload:hover {
color: #333;
}
.popup-search {
font-size: 1.4em;
text-align: center;
width: 100%;
}
.popup-notfound {
text-align: center;
color: #999
}
34 changes: 34 additions & 0 deletions src/components/addlocal/template.rt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="addlocal">
<header>
<button
onClick="()=>location.href='popup.html'"
class="popup-reload">
<i class="fa fa-arrow-left"></i>Back to Search
</button>
<h1>Manage your own local technical documents.</h1>
</header>
<h2>Newly add technical documents to your local environment.</h2>

Title:
<input
name="docTitle"
type="text"
value=""
/><br>
BaseUrl:
<input
name="baseUrl"
type="text"
value=""
/>[?]<br>
PageMatchingPattern:
<input
name="matchPattern"
type="text"
value=""
/>[?]<br>
<button onClick="()=>this.add()">Add</button>
<footer>
TechDocs
</footer>
</div>
4 changes: 3 additions & 1 deletion src/components/popup/template.rt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

<p rt-if="!this.state.searchString && this.props.translations.length == 0">
Is this a technical document?<br>
<a href="#" onClick="{this.goto.bind(this, this.props.contributingUrl)}">Let's make PR to add it to TechDocs!</a>
<a href="#" onClick="{this.goto.bind(this, this.props.contributingUrl)}">Let's make PR to add it to TechDocs!</a><br>
or<br>
<a href="addlocal.html">Add to your local list and use it.</a>
</p>

<p rt-if="!this.state.searchString && this.props.translations.length == 1">
Expand Down
12 changes: 12 additions & 0 deletions src/root/addlocal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en-US">

<head>
<title>Add to Local - TechDocs</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="addlocal.js"></script>
</head>

<body>TEST</body>

</html>