Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Mynij
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alexandra Rogova
Mynij
Commits
43722c16
Commit
43722c16
authored
May 28, 2019
by
Alexandra Rogova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test jio parser
parent
3d5b9c94
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
62 deletions
+161
-62
gadget_parser.js
gadget_parser.js
+103
-62
jio-parser-test.html
jio-parser-test.html
+12
-0
jio-parser-test.js
jio-parser-test.js
+46
-0
No files found.
gadget_parser.js
View file @
43722c16
...
...
@@ -6,28 +6,69 @@
.
declareAcquiredMethod
(
"
get_model
"
,
"
get_model
"
)
.
declareMethod
(
"
read_file
"
,
function
(
link
)
{
var
storage
;
.
setState
({
storage
:
null
})
.
ready
(
function
(){
var
gadget
=
this
;
gadget
.
get_model
()
.
push
(
function
(
result
)
{
storage
=
result
;
return
gadget
.
get_model
()
.
push
(
function
(
result
){
return
gadget
.
changeState
({
storage
:
result
});
});
})
.
push
(
function
()
{
.
declareMethod
(
"
read_file_new
"
,
function
(
link
){
var
gadget
=
this
;
return
gadget
.
get_rss
(
link
);
.
push
(
function
(
result
){
var
rss
,
title
;
rss
=
result
;
title
=
rss
.
slice
(
rss
.
indexOf
(
"
<title>
"
)
+
7
,
rss
.
indexOf
(
"
</title>
"
));
return
gadget
.
is_already_parsed
(
title
)
.
push
(
function
(
is_parsed
){
if
(
!
is_parsed
){
return
gadget
.
remove_css
(
rss
)
.
push
(
function
(
rss_without_css
){
return
gadget
.
state
.
storage
.
put
(
rss_without_css
);
});
}
});
});
})
.
declareMethod
(
"
get_rss
"
,
function
(
link
){
var
xmlhttp
=
new
XMLHttpRequest
();
xmlhttp
.
onreadystatechange
=
function
()
{
if
(
xmlhttp
.
status
==
200
&&
xmlhttp
.
readyState
==
4
)
{
var
cur_text
=
xmlhttp
.
responseText
,
if
(
xmlhttp
.
status
==
200
&&
xmlhttp
.
readyState
==
4
)
return
xmlhttp
.
responseText
;
else
return
null
;
}
xmlhttp
.
open
(
"
GET
"
,
link
,
true
);
xmlhttp
.
send
();
})
.
declareMethod
(
"
read_file
"
,
function
(
link
)
{
var
gadget
,
xmlhttp
,
cur_text
,
promise_list
=
[],
feed_title
;
gadget
=
this
;
xmlhttp
=
new
XMLHttpRequest
();
xmlhttp
.
onreadystatechange
=
function
()
{
if
(
xmlhttp
.
status
==
200
&&
xmlhttp
.
readyState
==
4
)
{
cur_text
=
xmlhttp
.
responseText
,
feed_title
=
cur_text
.
slice
(
cur_text
.
indexOf
(
"
<title>
"
)
+
7
,
cur_text
.
indexOf
(
"
</title>
"
));
gadget
.
is_already_parsed
(
storage
,
feed_title
)
return
gadget
.
is_already_parsed
(
feed_title
)
.
push
(
function
(
resultat
){
if
(
!
resultat
){
promise_list
.
push
(
storage
.
loaded_doc
(
feed_title
,
{
"
loaded
"
:
"
true
"
}));
promise_list
.
push
(
gadget
.
state
.
storage
.
loaded_doc
(
feed_title
,
{
"
loaded
"
:
"
true
"
}));
cur_text
=
cur_text
.
slice
(
cur_text
.
indexOf
(
"
<item>
"
),
cur_text
.
length
-
1
);
while
(
cur_text
.
indexOf
(
"
<item>
"
)
>
-
1
)
{
promise_list
.
push
(
gadget
.
parse
(
cur_text
,
storage
));
promise_list
.
push
(
gadget
.
parse
(
cur_text
));
cur_text
=
cur_text
.
slice
(
cur_text
.
indexOf
(
"
</item>
"
)
+
6
,
cur_text
.
length
-
1
);
}
RSVP
.
all
(
promise_list
);
...
...
@@ -38,9 +79,9 @@
xmlhttp
.
open
(
"
GET
"
,
link
,
true
);
xmlhttp
.
send
();
});
})
})
.
declareMethod
(
"
parse
"
,
function
(
local_cur_text
,
storage
)
{
.
declareMethod
(
"
parse
"
,
function
(
local_cur_text
)
{
var
title_start
=
local_cur_text
.
indexOf
(
"
<title>
"
)
+
7
,
title_end
=
local_cur_text
.
indexOf
(
"
</title>
"
),
link_start
=
local_cur_text
.
indexOf
(
"
<link>
"
)
+
6
,
...
...
@@ -49,28 +90,28 @@
body_end
=
local_cur_text
.
indexOf
(
"
</description>
"
)
+
14
;
return
this
.
remove_css
(
local_cur_text
.
slice
(
body_start
,
body_end
))
.
push
(
function
(
result
){
return
storage
.
put
({
return
gadget
.
state
.
storage
.
put
({
"
title
"
:
local_cur_text
.
slice
(
title_start
,
title_end
),
"
link
"
:
local_cur_text
.
slice
(
link_start
,
link_end
),
"
body
"
:
result
});
});
})
})
.
declareMethod
(
"
remove_css
"
,
function
(
body
){
.
declareMethod
(
"
remove_css
"
,
function
(
body
){
var
regEx
=
new
RegExp
(
'
(style="(.*?)"|style="(.*?)")
'
,
'
gi
'
);
return
body
.
replace
(
regEx
,
""
);
})
})
.
declareMethod
(
"
is_already_parsed
"
,
function
(
storage
,
title
){
return
storage
.
all_loaded_docs
()
.
declareMethod
(
"
is_already_parsed
"
,
function
(
title
){
return
this
.
state
.
storage
.
all_loaded_docs
()
.
push
(
function
(
result
){
var
i
;
for
(
i
=
0
;
i
<
result
.
data
.
rows
.
length
;
i
+=
1
){
if
(
result
.
data
.
rows
[
i
].
id
===
title
)
return
true
;
}
return
false
;
})
});
});
}(
window
,
RSVP
,
rJS
,
jIO
));
jio-parser-test.html
0 → 100644
View file @
43722c16
<!doctype html>
<html>
<head>
<title>
Jio parser test
</title>
<script
src=
"../jio/external/rsvp-2.0.4.js"
></script>
<script
src=
"../jio/dist/jio-latest.js"
></script>
<script
src=
"../renderjs/dist/renderjs-latest.js"
></script>
<script
src=
"jio-parser-test.js"
></script>
</head>
<body>
</body>
</html>
jio-parser-test.js
0 → 100644
View file @
43722c16
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, jIO*/
(
function
(
window
,
RSVP
,
rJS
,
jIO
)
{
"
use strict
"
;
rJS
(
window
)
.
ready
(
function
(){
var
gadget
=
this
;
gadget
.
test_storage
=
jIO
.
createJIO
({
type
:
"
parser
"
,
document_id
:
"
doc_id
"
,
attachment_id
:
"
att_id
"
,
parser
:
"
rss
"
,
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
test
"
}
});
return
gadget
.
test_storage
.
put
(
"
doc_id
"
,
{})
.
push
(
function
(){
return
gadget
.
get_test_rss
();
})
.
push
(
function
(
test_rss
){
return
gadget
.
test_storage
.
putAttachment
(
"
doc_id
"
,
"
att_id
"
,
new
Blob
([
test_rss
]));
})
.
push
(
function
(){
return
gadget
.
test_storage
.
get
(
"
doc_id
"
);
})
.
push
(
function
(
result
){
console
.
log
(
"
get result :
"
);
console
.
log
(
result
);
});
})
.
declareMethod
(
"
get_test_rss
"
,
function
(){
var
xmlhttp
=
new
XMLHttpRequest
();
xmlhttp
.
onreadystatechange
=
function
()
{
if
(
xmlhttp
.
status
==
200
&&
xmlhttp
.
readyState
==
4
)
return
xmlhttp
.
responseText
;
else
return
null
;
}
xmlhttp
.
open
(
"
GET
"
,
"
./test-files/vivelessvt.rss
"
,
true
);
xmlhttp
.
send
();
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment