Commit 792b80b46c376045a70dcfcc71f6e401615a3c09

  • avatar
  • arvind
  • Mon Aug 25 20:23:25 IST 2014
Refactor server.py to have a function call to inject JS and CSS for
annotator.
  • swtr/server.py 111 -----------------------------------------------------------------------------++++++++++++++++++++++++++++++++++
  • Diff rendering mode:
  • inline
  • side by side

swtr/server.py

138 root.make_links_absolute(flask.request.args['where'],138 root.make_links_absolute(flask.request.args['where'],
139 resolve_base_href=True)139 resolve_base_href=True)
140140
141 jQuery = root.makeelement('script')
142 root.body.append(jQuery)
143 jQuery.set("src", "//code.jquery.com/jquery-1.11.0.min.js")
144 jQuery.set("type", "text/javascript")
141 addScript("//code.jquery.com/jquery-1.11.0.min.js", root)
142 addScript(flask.url_for('static', filename="js/annotator-full.min.js"),
143 root)
145144
146 annotatorScript = root.makeelement('script')
147 root.body.append(annotatorScript)
148 annotatorScript.set("src", flask.url_for('static',
149 filename=
150 "js/annotator-full.min.js"))
151 annotatorScript.set("type", "text/javascript")
145 addCSS(flask.url_for('static', filename='css/annotator.min.css'), root)
146 addCSS(flask.url_for('static', filename='css/swtmaker.css'), root)
147 addCSS(flask.url_for('static', filename='css/bootstrap.min.css'), root)
148 addScript(flask.url_for('static',
149 filename="js/lib/underscore-1.5.2.min.js"),
150 root)
151 addScript(flask.url_for('static',
152 filename="js/lib/backbone-1.0.0.min.js"),
153 root)
154 addCSS(flask.url_for('static', filename='css/annotorious.css'), root)
155 addScript(flask.url_for('static',
156 filename="js/annotorious.okfn.0.3.js"),
157 root)
152158
153 annotatorCSS = root.makeelement('link')
154 root.body.append(annotatorCSS)
155 annotatorCSS.set("href", flask.url_for('static',
156 filename=
157 "css/annotator.min.css"))
158 annotatorCSS.set("rel", "stylesheet")
159 annotatorCSS.set("type", "text/css")
160
161 swtmakerCSS = root.makeelement('link')
162 root.body.append(swtmakerCSS)
163 swtmakerCSS.set("href", flask.url_for('static',
164 filename=
165 "css/swtmaker.css"))
166 swtmakerCSS.set("rel", "stylesheet")
167 swtmakerCSS.set("type", "text/css")
168
169 bootstrapCSS = root.makeelement('link')
170 root.body.append(bootstrapCSS)
171 bootstrapCSS.set("href", flask.url_for('static',
172 filename=
173 "css/bootstrap.min.css"))
174 bootstrapCSS.set("rel", "stylesheet")
175 bootstrapCSS.set("type", "text/css")
176
177 underscoreJS = root.makeelement('script')
178 root.body.append(underscoreJS)
179 underscoreJS.set("src", flask.url_for('static',
180 filename="js/lib/" +
181 "underscore-1.5.2.min.js"))
182 underscoreJS.set("type", "text/javascript")
183
184 backboneJS = root.makeelement('script')
185 root.body.append(backboneJS)
186 backboneJS.set("src", flask.url_for('static',
187 filename=
188 "js/lib/backbone-1.0.0.min.js"))
189 backboneJS.set("type", "text/javascript")
190
191 # annotorious plugin
192 annotoriousCSS = root.makeelement('link')
193 root.body.append(annotoriousCSS)
194 annotoriousCSS.set("href", flask.url_for('static',
195 filename='css/annotorious.css'))
196 annotoriousCSS.set('rel', 'stylesheet')
197
198 annotoriousJS = root.makeelement('script')
199 root.body.append(annotoriousJS)
200 annotoriousJS.set('src', flask.url_for('static',
201 filename='js/annotorious.okfn.0.3.js'))
202
203 if 'auth_tok' in session:159 if 'auth_tok' in session:
204 auth_tok = session['auth_tok']160 auth_tok = session['auth_tok']
205 else:161 else:
184 config.redirect_uri)184 config.redirect_uri)
185 configScript.set("type", "text/javascript")185 configScript.set("type", "text/javascript")
186186
187 # swtmakerScript = root.makeelement('script')
188 # root.body.append(swtmakerScript)
189 # swtmakerScript.set("src", flask.url_for('static',
190 # filename="js/swtmaker.js"))
191 # swtmakerScript.set("type", "text/javascript")
187 addScript(flask.url_for('static', filename="js/oauth.js"), root)
192188
193 oAuthScript = root.makeelement('script')
194 root.body.append(oAuthScript)
195 oAuthScript.set("src", flask.url_for('static',
196 filename="js/oauth.js"))
197 oAuthScript.set("type", "text/javascript")
189 addScript(flask.url_for('static', filename="js/app.js"), root)
198190
199 appScript = root.makeelement('script')
200 root.body.append(appScript)
201 appScript.set("src", flask.url_for('static',
202 filename="js/app.js"))
203 appScript.set("type", "text/javascript")
204
205 response = flask.make_response()191 response = flask.make_response()
206 response.data = lxml.html.tostring(root)192 response.data = lxml.html.tostring(root)
207 return response193 return response
203 refresh_token=auth_tok['refresh_token'],203 refresh_token=auth_tok['refresh_token'],
204 config=config,204 config=config,
205 url=flask.request.args.get('where'))205 url=flask.request.args.get('where'))
206
207
208def addScript(src, el):
209 script = el.makeelement('script')
210 el.body.append(script)
211 script.set("src", src)
212 script.set("type", "text/javascript")
213
214
215def addCSS(src, el):
216 style = el.makeelement('link')
217 el.body.append(style)
218 style.set("href", src)
219 style.set("rel", "stylesheet")
220 style.set("type", "text/css")
206221
207222
208# if the app is run directly from command-line223# if the app is run directly from command-line