How to override Materialize CSS in Ruby on Rails? [duplicate] - ruby-on-rails

I've been looking through some posts on the internet about Materialize in Rails, however this area seems to be very fuzzy. I am currently using the materialize-sass gem.
I didn't find very many helpful posts, I decided to resort here.
Here's my code for a page I have pages/discover.html.erb
<%= stylesheet_link_tag "https://fonts.googleapis.com/icon?family=Material+Icons" %>
<div class="row">
<div class="col s12 m5">
<div class="card">
<div class="card-image b">
<img src="http://i.huffpost.com/gen/1456585/images/o-CRAIG-COBB-facebook.jpg">
<span class="card-title">Cregg Cobb Is Back At It Again, But Only This Time He Has Guns</span>
</div>
<div class="card-content">
<p>I am a very simple card. I am good at containing small bits of information.
I am convenient because I require little markup to use effectively.</p>
</div>
<div class="card-action">
<div class="chip">
<img src="http://i.huffpost.com/gen/1456585/images/o-CRAIG-COBB-facebook.jpg" id="cobb">
Like
</div>
</div>
</div>
</div>
</div>
I want to make the <img> darker by using filter: brightness(50%);
How do I go about doing this? Where do I begin?
Bonus: If you know where I can add the jQuery stuff that Materializecss.com mentions when discussing components and transitions, it would be greatly appreciated!

Since it's just a single override, you could add a new .css file to assets (or wherever you're storing static stuff), with a !important class:
img.darker {
filter: brightness(50%) !important;
}
Then import it at the top of your template:
<%= stylesheet_link_tag "/path/to/css.file" %>
And add the class to your image tag:
<img src="/my/img.png" class="darker">
Alternatively you could just style the image tags individually:
<img src="/my/img.png" style="filter:brightness(50%)">

Related

How to get rid of the vertical gap between elements for some layouts?

I'm working on a web app with Bootstrap. In the mobile version it looks the way I want: the header on the top, below is a girl image, and below is the description of the application.
In desktop version I want to have header on top left, right under that description, and a girl image at the right side. Unfortunately, the girl image makes a big gap between the header and the description.
How can I get rid of that gap?
To recap, I want to move the description upper, to have it just under header, in that way.
Part of html, responsible for it:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<div class="container mt-lg-4">
<div class="row">
<p class="col-sm-6 mt-lg-5 mt-sm-1 h1"><strong>Find perfect product for your skin</strong></p>
<img src="https://via.placeholder.com/200" class="col-sm-6" />
<div id="description" class="col-sm-6">
PrimerAI will examine your skin and find the perfect product for your skin's needs.
</div>
</div>
</div>
You have two competing layouts here, involving not just ordering but containing structure. The simplest solution might be to repeat the image and show it as needed.
Also, use semantic elements in your page structure, like headings and paragraphs, to wrap text. It's important for accessibility and it's just good practice. The strong element is intended to add emphasis, but headings already have it so I've used CSS to get bold text.
.text-bold {
font-weight: bold;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<div class="container mt-lg-4">
<div class="row">
<div class="col-sm-6">
<h1 class="mt-lg-5 mt-sm-1 text-bold">Find perfect product for your skin</h1>
<img src="https://via.placeholder.com/500x600" class="img-fluid d-sm-none" />
<p id="description">
PrimerAI will examine your skin and find the perfect product for your skin's needs.
</p>
</div>
<div class="col-sm-6">
<img src="https://via.placeholder.com/500x600" class="img-fluid d-none d-sm-block" />
</div>
</div>
</div>
you can try that, I just add d-flex align-items-center to center verticaly the title with the image
<div class="container bg-success">
<div class="row">
<div class="col-md-6 d-flex align-items-center">
<h1>Find perfect product for your skin</h1>
</div>
<div class="col-md-6">
<img src="https://picsum.photos/id/1082/1000/1000?blur=8" class="img-fluid" />
</div>
<div>
PrimerAI will examine your skin and find the perfect product for your skin's needs.
</div>
</div>
</div>

Why does the image not show up whilst implementing Bootstrap for Ruby?

I am trying to implement bootstrap to my ruby application but failing to understand why the image is not displaying.
I am trying to implement this bootstrap. https://blackrockdigital.github.io/startbootstrap-clean-blog/.
The image is stored in Assets/Images
index.html.erb:
<!-- Page Header -->
<header class="masthead" <img class="img-responsive img-full" src="../assets/home-bg.jpg" alt="">
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="site-heading">
<h1>Start Bootstrap</h1>
<span class="subheading">Technology made simple in a blink of an eye!</span>
</div>
</div>
</div>
</div>
Current layout of page
If it is in the app/assets/images/ folder then just use the image tag.
<%= image_tag 'home-bg.jpg' %>
If you do not want to do that for some reason, then just inspect that page to see where it is looking for the image and adjust the path accordingly.

add an image tag in a div

I making a blog part with a buyed template.
I'm looking for add image in div. Something like that.
<div class="card card-raised card-background" style="background-image: url('<%= image_tag blog.couverture.url(:hd) %>')">
<div class="card-body">
...
Unfortunatly it's not working. So I looking for help after one hour of research on internet.
Thank you for you help.
Your image must be in "assets/images" folder on your rails proyect, then try this:
<div>
<img src="<%= asset_path 'image_name.format' %>" alt="">
</div>

How to extract article content from a website/blog

I'm trying to write a generic function for extracting article text from blog posts and websites.
A few simplified examples I'd like to be able to process:
Random website:
...
<div class="readAreaBox" id="readAreaBox">
<h1 itemprop="headline">title</h1>
<div class="chapter_update_time">time</div>
<div class="p" id="chapterContent">article text</div>
</div>
...
Wordpress:
<div id="main" class="site-main">
<div id="primary" class="site-content" role="main">
<div id="content" class="site-content" role="main">
<article id="post-1234" class="post-1234 post type-post">
<div class="entry-meta clear">..</div>
<h1 class="entry-title">title</h1>
<div class="entry-content clear">
article content
<div id="jp-post-flair" class="sharedaddy">sharing links</div>
</div>
</article>
</div>
</div>
</div>
Blogspot:
<div id="content">
...
<div class="main" id="main">
<div class="post hentry">
<h3 class="post-title">title</h3>
<div class="post-header">...</div>
<div class="post-body">article content</div>
<div class="post-footer">...</div>
</div>
</div>
</div>
What I came up with (doc is a Nokogiri::HTML::Document):
def fetch_content
html = ''
['#content', '#main', 'article', '.post-body', '.entry-content', '#chapterContent'].each do |css|
candidate = doc.css(css).to_html
html = [html, candidate].select(&:present?).sort_by(&:length).first
end
self.content = html
end
It works relatively well for the examples I tested with but it still leaves some sharing and navigation links plus it won't work if a page uses more cryptic class names.
Is there a better way to do this?
There is a gem called pismo that implements a couple of algorithms that attempts to extract article content.
There is a java library boilerpipe which you can interface from JRuby which extract textual content of a webpage.
Use rapar this gives the facility to write domain specific parser like wordpress.com, blogspot.com etc
You could also use a free article extraction API, for example:
diffbot.com
embed.ly
textracto.com
Some of them work quite good, and as I know there are all easy to integrate with Ruby.

Rails Bootstrap .span not working

I am learning Rails and I am using bootstrap-sass gem. My layout looks like this:
<main role="main">
<div class="container">
<div class="content">
<div class="row">
<div class="span3">
LEFT
</div>
<div class="span9">
<%= render 'layouts/messages' %>
<%= yield %>
</div>
</div>
<footer>
</footer>
</div>
</div>
</main>
The problem is that each of the two columns, .span3 and .span 9 are shown full width and one beneath the other. This is the same for any .span combination.
What am I doing wrong?
Thanks!
You might be using bootstrap 2 syntax with bootstrap 3. span9 changed to col-md-9 (its not exactly like that, see getbootstrap.com for details on how the new grid works).
Which version of bootstrap are you using? If it's bootstrap version 3 it's switched to col-md-xx. So you probably need to use col-md-3 & col-md-9.

Resources