Pattern Matching Function (Ruby)
def hilite_search_criteria(pattern, search_criteria)
return if pattern.nil? or search_criteria.nil?
pattern.gsub!(/(<[^>]*>)|\n|\t/s) {” “}
match_char = pattern =~ /#{search_criteria}/i
matched_string = $~.to_s
return if match_char.nil?
start = match_char – 25
start = (start < 0 ? 0 : start)
unless match_char.nil?
p = pattern[start ... match_char + search_criteria.length + 25]
match_char = pattern =~ /#{search_criteria}/i
p[match_char, matched_string.length ] = '‘ + matched_string + “”
return p
end
end
More Stories
Hello Stimulus JS
When what you’re building is Rails with light interactions, marketing pages, landing pages, dashboard apps on Rails 7, Stimulus JS is exactly what you want. It gets out of your way just the right amount, making the easy easy and the hard possible
When Rails Ejected Node and the History of Compiled JS in Rails
Explore the history of Sprockets, Webpack, and Webpacker in Rails and understand why Rails 7 no longer has webpack by default.
Sitemaps on an External S3 Bucket using an Asset Subdomain for 2022
it is still possible to host your sitemap on external S3 buckets. You must set up a subdomain of your domain pointed as an Alternative Domain Name for your CloudFront distribution, and in order to do this you must go through domain verification with AWS.
Why You Need a Special DNS Provider on Heroku
Heroku is a robust leader in 12-factor deployment strategies. It is a large and feature-rich platform. You can deploy your...
The How and Why of End-to-End Testing
Tested codebases are the most signficiant development from Rails and Agile over the last 15 years. End-to-end testing, in particular, is the defining reason why Agile and Rails have been so successful. Not writing tests should be seen as akin to malpractice in software development. Hiring someone to write untested code should be outlawed.