updates to scala documentation viewer
--HG-- branch : pmacs2
This commit is contained in:
parent
8f82922870
commit
30c093411d
|
@ -755,8 +755,11 @@ class Application(object):
|
||||||
|
|
||||||
# running external programs
|
# running external programs
|
||||||
def run_pipe(self, args, b, name='*Output*', switch=True, modename=None):
|
def run_pipe(self, args, b, name='*Output*', switch=True, modename=None):
|
||||||
pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
#pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
||||||
data = b.make_string().encode('utf-8')
|
data = b.make_string().encode('utf-8')
|
||||||
|
return self.run_pipe2(args, data, name, switch, modename)
|
||||||
|
def run_pipe2(self, args, data, name='*Output*', switch=True, modename=None):
|
||||||
|
pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
||||||
try:
|
try:
|
||||||
pipe.stdin.write(data)
|
pipe.stdin.write(data)
|
||||||
pipe.stdin.close()
|
pipe.stdin.close()
|
||||||
|
@ -770,7 +773,8 @@ class Application(object):
|
||||||
switch_to = switch(status)
|
switch_to = switch(status)
|
||||||
else:
|
else:
|
||||||
switch_to = bool(switch)
|
switch_to = bool(switch)
|
||||||
self.data_buffer(name, output, switch_to=switch_to, modename=modename)
|
self.data_buffer(name, output.decode('utf-8'), switch_to=switch_to,
|
||||||
|
modename=modename)
|
||||||
return status
|
return status
|
||||||
def run_external(self, *args):
|
def run_external(self, *args):
|
||||||
curses.reset_shell_mode()
|
curses.reset_shell_mode()
|
||||||
|
|
|
@ -107,24 +107,39 @@ class ScalaDocBrowse(Method):
|
||||||
class ScalaDocLookup(Method):
|
class ScalaDocLookup(Method):
|
||||||
args = [arg('name', t='string', p='Name: ', dv=default.current_word,
|
args = [arg('name', t='string', p='Name: ', dv=default.current_word,
|
||||||
ld=True, h='The Scala name to get help on')]
|
ld=True, h='The Scala name to get help on')]
|
||||||
|
def _get_path(self, w, name):
|
||||||
|
return w.application.getpath('cache', 'scala', name)
|
||||||
|
def _get_url(self, w, name, url):
|
||||||
|
path = self._get_path(w, name)
|
||||||
|
w.application.mkdirs('cache', 'scala')
|
||||||
|
|
||||||
|
if not os.path.exists(path):
|
||||||
|
open(path, 'w').write(urllib2.urlopen(url).read())
|
||||||
|
|
||||||
|
html = open(path, 'r').read()
|
||||||
|
return html
|
||||||
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
try:
|
try:
|
||||||
import BeautifulSoup
|
from BeautifulSoup import BeautifulSoup
|
||||||
except ImportError:
|
except ImportError:
|
||||||
w.set_error('BeautifulSoup is not installed...')
|
w.set_error('BeautifulSoup is not installed...')
|
||||||
return
|
return
|
||||||
|
|
||||||
a = w.application
|
a = w.application
|
||||||
name = vargs.get('name')
|
name = vargs.get('name')
|
||||||
path = a.getpath('cache', 'scala', 'api.html')
|
html = self._get_url(w, 'api.html', a.config['scala.api'])
|
||||||
url = a.config['scala.api']
|
soup = BeautifulSoup(html)
|
||||||
|
|
||||||
a.mkdirs('cache', 'scala')
|
tags = soup.findAll('li')
|
||||||
|
for li in tags:
|
||||||
|
if li['title'].endswith(name):
|
||||||
|
frag = li.contents[0]['href']
|
||||||
|
url2 = a.config['scala.api-base'] + '/' + frag
|
||||||
|
a.run_external('links', url2)
|
||||||
|
return
|
||||||
|
|
||||||
if not os.path.exists(path):
|
w.set_error('error looking up %s...' % name)
|
||||||
open(path, 'w').write(urllib2.urlopen(url).read())
|
|
||||||
|
|
||||||
w.set_error('looking up %s...' % name)
|
|
||||||
|
|
||||||
# white is for delimiters, operators, numbers
|
# white is for delimiters, operators, numbers
|
||||||
default = ('default', 'default')
|
default = ('default', 'default')
|
||||||
|
@ -171,6 +186,7 @@ class Scala(Fundamental):
|
||||||
closetags = {')': '(', ']': '[', '}': '{'}
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
config = {
|
config = {
|
||||||
'scala.api': 'http://www.scala-lang.org/api/current/allclasses.html',
|
'scala.api': 'http://www.scala-lang.org/api/current/allclasses.html',
|
||||||
|
'scala.api-base': 'http://www.scala-lang.org/api/current',
|
||||||
}
|
}
|
||||||
|
|
||||||
colors = {
|
colors = {
|
||||||
|
|
Loading…
Reference in New Issue