【发布时间】:2013-02-02 15:07:38
【问题描述】:
上面有一个projects.html文件。这个文件成功了,但是当我用http://html2haml.heroku.com/将此html文件转换为haml文件时,haml文件不起作用。
你能看出两个文件之间的区别吗?
projects.html.erb
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Sectoral Statistics'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}% - {point.y} proje</b> ',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' % - '+ this.y +' proje';
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
<% @results.each do |key,value| %>
['<%= key %>',<%= value %>,<%= value %>],
<% end %>
]
}]
});
});
});
</script>
projects.html.haml
%script{:src => "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", :type => "text/javascript"}
%script{:src => "http://code.highcharts.com/highcharts.js"}
%script{:src => "http://code.highcharts.com/modules/exporting.js"}
:javascript
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Sectoral Statistics'
},
tooltip: {
pointFormat: '{series.name}: {point.percentage}% - {point.y} proje ',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return ''+ this.point.name +': '+ Math.round(this.percentage) +' % - '+ this.y +' proje';
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
@results.each do |key,value|
[' key ', value , value ],
]
}]
});
});
});
【问题讨论】:
-
在我看来更像是顶部带有 HTML 标记的 Javascript。你打算在 Rails 项目中使用它吗?
-
是的,它实际上是关于带有 html 的 javascript 但我将在 rails 项目中使用它
-
我建议将您的 js 从视图模板移动到单独的文件中,并将这些文件包含在清单文件
application.js中。在您的情况下,HTML2HAML 无法正确转换。您可以搜索asset-pipelinein this RailsGuide,您将了解 Rails 组织您的js和css的方式。
标签: ruby-on-rails highcharts haml