0

这个问题说了 1000 个单词,但我基本上想做的是构建一个 Locomotive CMS 插件,而我只停留在基础知识上。这不是一件好事。

我已按照此 gem 的说明进行操作,因为它是我能找到的唯一参考资料: https ://github.com/colibri-software/locomotive_plugins

我已添加locomotive_plugins到我的 gemfile 中。我制作了一个名为的文件locomotive_test_plugin.rb并将其放在我的lib文件夹中(我发现这是放置此文件的合乎逻辑的地方,因为它在 gem 说明中没有明确说明)。我确实将lib文件夹添加config.autoload_pathsapplication.rb. 我有点希望它会起作用

locomotive_test_plugin.rb 看起来像

class LocomotiveTestPlugin
  include Locomotive::Plugin

  def initialize_plugin
    # Custom initialization code
  end

  def to_liquid
    {:test => "test"}
  end
end

LocomotivePlugins::register_plugin(LocomotiveTestPlugin, "test_plugin")

事实证明它没有。我还定制了一个gem名为locomotive_test_plugin并安装了 gem 并将该 gem 添加到 Gemfile 中,例如:

source 'https://rubygems.org'

gem 'locomotive_cms', '~> 2.0.1', :require => 'locomotive/engine'
gem 'locomotive_plugins'

group :assets do
  gem 'compass-rails',  '~> 1.0.2'
  gem 'sass-rails',     '~> 3.2.4'
  gem 'coffee-rails',   '~> 3.2.2'
  gem 'uglifier',       '~> 1.2.4'

  # If you run your engine on **Linux,** you also have to add the following gem
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby
end

group :development do
  gem 'unicorn'
end

group(:locomotive_plugins) do
  gem 'locomotive_test_plugin'
end

根据 gem,我现在可以在 CMS 中编辑任何页面并添加以下液体代码:

{{ plugins.test_plugin.test }}

我希望输出是“测试”,但它什么也没显示。它也不会显示任何错误,例如“找不到插件”或类似的东西。

如果有人建议,我已经重新启动了本地服务器。

但是在这个过程中我哪里出错了 - 任何人都可以在这个问题上启发我。

4

1 回答 1

2

一、线

LocomotivePlugins::register_plugin(LocomotiveTestPlugin, "test_plugin")

不需要。那是来自旧版本的插件。至于您的问题,您是否在您的网站上启用了该插件?您需要转到设置页面,有一个名为插件的折叠部分,在该部分下应该有一个带有复选框的条目。确保选中该框。

如果条目未显示,则插件未正确加载。确保在启动服务器时加载您的代码(在顶部添加打印 stmt)。

于 2013-07-01T21:33:45.967 回答