Cleaned up some overcomplicated code

This commit is contained in:
Emi Simpson 2019-12-05 20:20:09 -05:00
parent 13bacb4320
commit ab65b44f0d
No known key found for this signature in database
GPG Key ID: 68FAB2E2E6DFC98B
2 changed files with 19 additions and 28 deletions

View File

@ -8,7 +8,6 @@ use html5ever::{local_name, namespace_url, ns};
use http::retrieve_asset; use http::retrieve_asset;
use js::attr_is_event_handler; use js::attr_is_event_handler;
use std::fmt::Write as OtherWrite; use std::fmt::Write as OtherWrite;
use std::io::{stderr, Write};
use std::collections::HashMap; use std::collections::HashMap;
use std::default::Default; use std::default::Default;
use utils::{data_to_dataurl, is_valid_url, resolve_css_imports, resolve_url, url_has_protocol}; use utils::{data_to_dataurl, is_valid_url, resolve_css_imports, resolve_url, url_has_protocol};
@ -154,11 +153,10 @@ pub fn walk_and_embed_assets(
// If a network error occured, warn // If a network error occured, warn
Err(e) => { Err(e) => {
writeln!( eprintln!(
stderr(),
"Warning: {}", "Warning: {}",
e, e,
).unwrap(); );
//If failed to resolve, replace with absolute URL //If failed to resolve, replace with absolute URL
href_full_url href_full_url
@ -301,8 +299,7 @@ pub fn walk_and_embed_assets(
node.children.borrow_mut().clear(); node.children.borrow_mut().clear();
} else { } else {
for node in node.children.borrow_mut().iter_mut() { for node in node.children.borrow_mut().iter_mut() {
match node.data { if let NodeData::Text{ref contents} = node.data {
NodeData::Text {ref contents} => {
let mut tendril = contents.borrow_mut(); let mut tendril = contents.borrow_mut();
let replacement = resolve_css_imports( let replacement = resolve_css_imports(
cache, cache,
@ -316,8 +313,6 @@ pub fn walk_and_embed_assets(
tendril.clear(); tendril.clear();
tendril.write_str(&replacement) tendril.write_str(&replacement)
.expect("Failed to update DOM"); .expect("Failed to update DOM");
},
_ => (),
} }
} }
} }

View File

@ -4,10 +4,7 @@ use self::base64::encode;
use http::retrieve_asset; use http::retrieve_asset;
use regex::Regex; use regex::Regex;
use url::{ParseError, Url}; use url::{ParseError, Url};
use std::{ use std::collections::HashMap;
io::{stderr, Write},
collections::HashMap,
};
lazy_static! { lazy_static! {
static ref HAS_PROTOCOL: Regex = Regex::new(r"^[a-z0-9]+:").unwrap(); static ref HAS_PROTOCOL: Regex = Regex::new(r"^[a-z0-9]+:").unwrap();
@ -137,11 +134,10 @@ pub fn resolve_css_imports(
).map(|(a, _)| a), ).map(|(a, _)| a),
}.unwrap_or_else(|e| { }.unwrap_or_else(|e| {
writeln!( eprintln!(
stderr(),
"Warning: {}", "Warning: {}",
e, e,
).unwrap(); );
//If failed to resolve, replace with absolute URL //If failed to resolve, replace with absolute URL
embedded_url embedded_url