Ruby on rails 将html转换为haml
上面有一个projects.html文件。该文件工作正常,但当我使用将该html文件转换为haml文件时,haml文件不工作 你能看出这两个文件有什么不同吗 projects.html.erbRuby on rails 将html转换为haml,ruby-on-rails,highcharts,haml,Ruby On Rails,Highcharts,Haml,上面有一个projects.html文件。该文件工作正常,但当我使用将该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.hi
<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>
我认为这是
html2haml
中的一个bug
在HTML中,您的最后一个脚本标记类似于以下内容(为了简洁起见,我将其删减):
最后一行–})代码>–未缩进
要解决这个问题,您应该在HTML或生成的Haml中修复缩进
请注意,:javascript
中有一些过滤器您应该注意。它认为在这种情况下,您应该可以使用它。我认为这是html2haml
中的一个bug
在HTML中,您的最后一个脚本标记类似于以下内容(为了简洁起见,我将其删减):
最后一行–})代码>–未缩进
要解决这个问题,您应该在HTML或生成的Haml中修复缩进
请注意,:javascript
中有一些过滤器您应该注意。它认为在这种情况下,您应该可以使用它。在我看来,它更像是顶部带有HTML标记的Javascript。你打算在Rails项目中使用它吗?是的,它实际上是关于带html的javascript,但我将在Rails项目中使用它。我建议将js从视图模板移动到单独的文件中,并将这些文件包含在清单文件application.js
中。HTML2HAML在您的情况下无法正确转换。您可以搜索资产管道
,您将了解Rails如何组织您的js
和css
。在我看来,它更像是顶部带有HTML标记的Javascript。你打算在Rails项目中使用它吗?是的,它实际上是关于带html的javascript,但我将在Rails项目中使用它。我建议将js从视图模板移动到单独的文件中,并将这些文件包含在清单文件application.js
中。HTML2HAML在您的情况下无法正确转换。您可以搜索资产管道
,您将了解Rails如何组织您的js
和css
。
%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 ],
]
}]
});
});
});
<script type="text/javascript">
$(function () {
...
});
</script>
:javascript
$(function () {
...
});