這個問題說1000字,但我基本上想要做的是構建一個機車CMS插件,我堅持的基礎知識。這不是一件好事。如何設置一個基本的機車CMS插件
我跟了這寶石的指示,因爲它的參考的唯一一件我能找到的: https://github.com/colibri-software/locomotive_plugins
我添加locomotive_plugins
我的Gemfile。我創建了一個名爲locomotive_test_plugin.rb
的文件,並將其放在我的lib
文件夾中(我發現這是放置此文件的合理位置,因爲它沒有在gem說明中明確說明)。我確實將lib
文件夾添加到application.rb
中的config.autoload_paths
。我有點希望,它將工作
的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
並安裝了寶石,並補充說寶石的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
根據創業板現在我可以在CMS編輯任何頁面,並添加下面的一段液體的代碼:
{{ plugins.test_plugin.test }}
而且我期望輸出是「測試」,但它不顯示任何內容。它也不會顯示任何錯誤,比如'找不到插件'或類似的東西。
我已經重新啓動本地服務器,如果有人會建議。
但是在這個過程中,哪裏出了問題 - 任何人都可以在這個問題上啓發我。不需要