Generate PDF based on Particular Div id in Rails - ruby-on-rails-4

Is there a way to generate pdf in rails based on div id.
Sample code:
<div id="pdf_download">
<h1>Hello Welcome to PDF
</div>
<div id="seconf_pdf">
<h2>Second PDF</h2>
</div>
Now i want to download only the div id "pdf_download" as pdf, Is it possible? Can anyone explain how to achieve it?

There seems to be a gem that does that - wicked_pdf. Internally it seems to depend on wkhtmltopdf, so you should be able to install this on your production environment.

Related

django Download Link(filefield)

i am trying to create a Software download website, and each software has some file and download link (mac,windows,linux,..).
Can anyone tell me how to use 'filefield' for download links(not one).
(Sorry, my English is so weak).
You just need to put download attribute in the anchor tag . and the anchor tag will allow the user to get the file from the href location. A small example is give below
<a download href="/media/{{friend.picture}}"><img height="100%" width="100%" class="img-fluid d-block mx-auto" src="/media/{{friend.picture}}"></a>

Add Facebook share button to Django application

I am using Facebook's share button on my Django app.
I'm using Facebook's SKD instructions which tell me to place this code wherever you want the plugin to appear on your page:
<div class="fb-share-button"
data-href="https://my-website-full-url"
data-layout="button" data-size="small" data-mobile-iframe="false">
<a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&src=sdkpreparse">Share
</a>
</div>
So I placed that code in my template but how do I add the full URL of the web page with the FB share button in the data-href attribute?
As long as you have django.template.context_processors.request enabled you should be able to use request.build_absolute_uri() in your template:
data-href="{{ request.build_absolute_uri }}"
This should work out of the box if you're using a fairly recent version of Django.

Web Scraping with python and scrapy

I'm trying to scrap a site with this types of div:
<div class="mindatath">Density:</div>
<div class="mindatam2">
3.98 - 4.1 g/cm
<sup>3</sup>
(Measured) 3.997 g/cm
<sup>3</sup>
(Calculated)
</div>
</div>
Ok, I need the value in mindatam2 div. But exist a lot of divs with this class. How can I relate the two divs to I know what the value to extract?
I try with Scrapy to show all divs values:
response.xpath('//div[#class="mindatam2"]/text()').extract()
If all your densities have similar format, you can use regex
For example
response.xpath('//div[#class="mindatam2"]/text()').re(r'([\d\.\-\s]+)g/cm')

How to remove Billing details, Delivery details and Delivery method from opencart 2.1.0.1 version

Hello I am using Opencart version 2.1.0.1 and i want to keep only Payment Method on my site.So How can i remove it. I tried
OpenCart 2.0: How To Remove Billing Details from Chekout Page
this post but not helpfull for me.
Basically I am getting
$('#payment-address .checkout-content').html(html);
$('#payment-address .checkout-content').slideDown('slow');
These 2 lines in checkout.tpl
in the file /catalog/view/theme/bazien/template/checkout/checkout.tpl i change panel of payment method to none display
<div style="display: none;">
<div class="panel-collapse collapse" id="collapse-payment-method">
<div class="panel-body"></div>
</div>
</div>
and then i change this code
$('a[href=\'#collapse-payment-method\']').trigger('click');
to this code
$('#button-payment-method').trigger('click');
and it's working.
on opencart 2.0.3.1 was tested.

Is there a way to have (hack) turbolinks to only refresh a specific selector?

I would like to use turbolinks in a rails 4 application but not have it replace the entire <body> tag. Instead I would like to specify a tag/selector for turbolinks to refresh.
Something like...
<body>
<div class="turbolinks-refreshes-this">
Some content that is replaced whenever a link is clicked.
</div>
<div class="turblinks-does-not-refresh-this">
Some content that remains even if a link is clicked.
</div>
</body>
My guess is you would need to fork turbolinks to add this functionality but thought I'd throw it out there to see if anyone else has tried to do this.
Have you looked at pjax? It's very similar to Turbolinks (and gets a mention in the Turbolinks README) but lets you specify a target container. Here's a Railscast that shows how to use it in a Rails app.
Here's a (slightly modified) excerpt from the pjax README:
<h1>My Site</h1>
<div class="container" id="pjax-container">
Go to next page.
</div>
We want pjax to grab the url /page/2 then replace #pjax-container
with whatever it gets back. No styles or scripts will be reloaded and
even the h1 can stay the same - we just want to change the
#pjax-container element.
We do this by telling pjax to listen on a tags and use
#pjax-container as the target container:
$(document).pjax('a', '#pjax-container')
Now when someone in a pjax-compatible browser clicks "next page" the
content of #pjax-container will be replaced with the body of
/page/2.