プログラミング

csvから簡単にwordpressのadd_shortcodeを作成する

投稿日:

csvから簡単にwordpressのadd_shortcodeを作成するジェネレータを作ったので公開してみる.

usage

git clone https://github.com/yuis-ice/wp_shortcode_genelater.git

あとはこちらのREADMEを読んで下さい.
https://github.com/yuis-ice/wp_shortcode_genelater

コード


require 'csv' @csvFilePath=File.expand_path('../../src.csv', __FILE__) @functions='' CSV.foreach(@csvFilePath, headers: true) do |csvText| # ASP # CATEGORY # REMARKS # PRODUCT # TAG # AD if csvText['ASP'] then csvText['ASP'].gsub!(/\n/,'') end if csvText['CATEGORY'] then csvText['CATEGORY'].gsub!(/\n/,'') end if csvText['REMARKS'] then csvText['REMARKS'].gsub!(/\n/,'') end if csvText['PRODUCT'] then csvText['PRODUCT'].gsub!(/\n/,'') end if csvText['TAG'] then csvText['TAG'].gsub!(/\n/,'') end if csvText['AD'] then csvText['AD'].gsub!(/\n/,'') end @functions += " // ASP: #{csvText['ASP']} // CATEGORY: #{csvText['CATEGORY']} // REMARKS: #{csvText['REMARKS']} // PRODUCT: #{csvText['PRODUCT']} function #{csvText['TAG']}(){ return '#{csvText['AD']}' ; } add_shortcode('#{csvText['TAG']}', '#{csvText['TAG']}') ; " end puts @functions @resultFilePath=File.expand_path('../../output/result.txt', __FILE__) File.open(@resultFilePath,'w'){|file| file.puts @functions }

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です